@mdip/ipfs
v2.2.0
Published
MDIP IPFS lib
Downloads
980
Readme
MDIP IPFS
MDIP utilities for integrating with IPFS.
Installation
npm install @mdip/ipfsUsage
Basic use
import HeliaClient from '@mdip/ipfs/helia';
const ipfs = new HeliaClient();
await ipfs.start();
const data = { data: 'whatever' };
const cid = await ipfs.addJSON(data);
const retrieve = await ipfs.getJSON(cid); // retrieve == data
await ipfs.stop();Create factory
The static factory method create can be used to create and start an IPFS instance:
const ipfs = await HeliaClient.create();FS blockstore mode
Passing datadir to the constructor or create will persist data to the specified folder.
const ipfs = await HeliaClient.create({ datadir: 'data/ipfs' });Minimal mode
Starting IPFS in minimal mode avoids starting a Helia IPFS server.
The addJSON, addText, and addData methods still generate CIDs. Nothing is persisted, so the corresponding get methods throw NotConnectedError.
const ipfs = await HeliaClient.create({ minimal: true });