igun997/ipfs-interpolar

Laravel Accessor for IPFS

0.0.4 2021-04-24 10:01 UTC

This package is not auto-updated.

Last update: 2024-05-05 16:12:52 UTC


README

This is a simple library to access IPFS services in Laravel. It works via use of the HTTP API to give simple access to IPFS functions including navigating content, retreiving pictures and files, and adding text and files to the IPFS network.

Installing

This library requires the cURL module:

$ sudo apt-get install php7.2-curl
$ composer require igun997/ipfs-interpolar
$ php artisan vendor:publish

Please see /config/ipfs.php in your app to configure the API server and relevant ports. It is strongly recommended to run a local IPFS Instance. In Ubuntu Linux, you will be able to run sudo apt install ipfs to get a compatible version.

use Igun997\LaravelIPFS\IPFS;

// connect to local daemon API server
$ipfs = new IPFS("localhost", "8080", "5001");

Note that if you are using a Docker container via docker-compose (please see docker-compose.sample.yml for an example that should work with a simple Laravel project using an SQL database), then you will need to use "ipfs" rather than "localhost" as the server name.

API

add

Adds content to IPFS.

$hash = $ipfs->add("Hello world");
var_dump($hash); // QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG

cat

Retrieves the contents of a single hash.

$ipfs->cat('Qmbgm7f1uTESdUdddaSeV3mMT5nSQ7GijN2Hb7nCRj6oTe');

ls

Gets the node structure of a hash.

$obj = $ipfs->ls($hash);

foreach ($obj as $e) {
	echo $e['Hash'];
	echo $e['Size'];
	echo $e['Name'];
}

pin

Pin or unpin a hash.

$ipfs->pinAdd($hash);
$ipfs->pinRm($hash);

size

Returns object size.

$size = $ipfs->size($hash);

Pin

Get information about your ipfs node.

print_r($ipfs->id());