Simple library which wraps some basic IPFS kubo RPC api calls into simple functions. Check detail documentation for IPFS kubo RPC api here
- node.js 16.17.0 or higher
Library can be used via Git import and is not accessible on NPM.
Add below code to package.json
in dependency section, to install library in your project.
{
...
"@apillon/ipfs-kubo-rpc-http-client": "github:Apillon/ipfs-kubo-rpc-http-client",
...
}
Library is working directly with IPFS kubo RPC api. Initialize client like so:
const client = new IpfsKuboRpcHttpClient(process.env.RPC_API_URL);
To upload data to IPFS use client.add method, which expects content as parameter. Content is of type any
.
As a response, library returns instance of IAddResult
interface with Hash
and Size
properties.
await client.add({ content: "Some test content on IPFS" });
Because files in IPFS are content-addressed and immutable, they can be complicated to edit. Mutable File System (MFS) is a tool built into IPFS that lets you treat files like you would a regular name-based filesystem.
Files
class implements below methods, to work with MFS:
- write: write content to IPFS MFS
- ls: list all entries for path
- stat: get properties of a object in a given path
Example of writing content to MFS:
await client.files.write({
content: "This is file in MFS",
path: "/path-to-file/My MFS file.txt",
});
The InterPlanetary Name System (IPNS) is a system for creating mutable pointers to CIDs known as names or IPNS names. IPNS names can be thought of as links that can be updated over time, while retaining the verifiability of content addressing.
Name
class implements below methods, to work with IPNS.
- publish: publish CID to IPNS. In order to publish CID to IPNS, key is required. It can be generated using
Key
class, with methodgen
.
Pinning is the mechanism that allows you to tell IPFS to always keep a given object somewhere — the default being your local node.
Pin
class implements below methods, to manage pinned files on IPFS node:
- add: pin path(file) to ipfs node
- ls: list pinned files
- rm: unpin given path(file) from node
Pin CID example:
await client.pin.add({
cids: ["bafkreiakrvel4n4dd3jirros2dbow7jvtrdtfq2pbj6i7g6qpf64krmqfe"],
});
Library return instance of ClientError
class if error (client or API) occurs.
Error has below properties:
field | description |
---|---|
status | status code returned from request to RPC API or 400 for client errors |
statusText | additional info about status |
message | error message |
We welcome contributions to the Apillon ipfs-kubo-rpc-http-client! If you would like to contribute, please follow these steps:
- Fork this repository.
- Clone your forked repository to your local machine.
- Install the dependencies by running npm install.
- Make your changes and write tests to ensure they work.
- Commit your changes and push them to your forked repository.
- Open a pull request to this repository.
Before submitting a pull request, please make sure to run the tests by running npm test. We also recommend running npm run lint to ensure your code follows our coding standards.
This project is licensed under the MIT License - see the LICENSE file for details.