sdkjs

Installation

To install ripio sdk-storage-ipfs we recommend node 16 or above, although it might work with lower versions.

npm install @ripio/sdk-storage-ipfs

Overview

StorageIpfs

When working with NFTs a good practice is to store your NFTs data on Ipfs, which is a protocol and peer-to-peer network for storing and sharing data in a distributed file system. For this reason a StorageIpfs class is given:

// commonJS
const { StorageIpfs } = require('@ripio/sdk-storage-ipfs');
// TS
import { StorageIpfs } from '@ripio/sdk-storage-ipfs';
// Create StorageIpfs instance
const ipfs = new StorageIpfs(IPFS_URL);

Where IPFS_URL is the api gateway to a node.

The StorageIpfs class arranges a variety of methods to interact with the ipfs nodes:

await ipfs.storeFile(./images/cat.png);
QmjEhb // CID of the file
const data = {image: 'QmP…Weh', {description: Marvin the Paranoid Android} };
await ipfs.storeMetadata(data);
QmjEhb
const resource = await ipfs.getData(QmjEhb);
await resource.getStringData();
Marvin the Paranoid Android
const resource = await ipfs.getData(QmjEhb);
await resource.getJsonData();
{image: 'ipfs://fake-uri/image.png', level: 42, name: 'Marvin'}
const resource = await ipfs.getData(QmjEhb);
await resource.getBase64Data();
RWwgc2VudGlkbyBkZSBsYSB2aWRhLCBlbCB1bml2ZXJzbyB5IHRvZG8gbG8gZGVtw6Fz

Other resources