vier/ipfs-api

A minimal implementation of IPFS API

This package's canonical repository appears to be gone and the package has been frozen as a result.

dev-master 2022-03-29 11:23 UTC

This package is not auto-updated.

Last update: 2024-01-13 01:23:51 UTC


README

A minimal implementation of IPFS API.

使用说明

安装

This library requires PHP 5.7 and the curl and json extensions.

$ composer require vier/ipfs-api:dev-master
$ composer install
use vier\IpfsApi\Ipfs;
// connect to ipfs daemon API server
$ipfs = new IPFS("localhost", 5001, "http://yourdomain/ipfs"); // leaving out the arguments will default to these values

API

add

Adds content to IPFS.

Usage

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

addFromPath

Adds content to IPFS from a filename (helper method)

Usage

$hash = $ipfs->addFromPath("myFile.txt");

addFromUrl

Adds content ot IPFS from a web URL (helper method)

Usage

$hash = $ipfs->addFromUrl('https://mysite.com/img.png');

get

Retrieves the contents of a single hash.

Usage

$ipfs->get($hash);

ls

Gets the node structure of a hash.

Usage

$nodes = $ipfs->ls($hash);
foreach ($nodes as $node) {
	echo $node['Hash'];
	echo $node['Size'];
	echo $node['Name'];
}

Object size

Returns object size.

Usage

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

Pin

Pin or unpin a hash.

Usage

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

ID

Get information about your ipfs node.

Usage

print_r($ipfs->id());