Skip to main content

IPFS Service

The IPFS service provides methods to upload and read files from IPFS.

We use web3.storage to store files on IPFS.You need a API Token form their service.

IPFS simply is a distributed file system that allows you to store files on a network of computers. The files are stored in a content-addressable way, which means that the content of the file is used to generate a unique identifier for the file. This identifier is called a CID (Content Identifier). The CID is used to retrieve the file from the network.

storeFiles

Uploads files to IPFS and returns the CID of the root directory.

storeFiles(path: string, bulkUpload: boolean): Promise<CIDString>
import { IPFS } from 'mquark-sdk';

const path = __dirname + "/my-exmple-nft-metadata.json" // path to the file that you want to upload
const API_TOKEN = 'YOUR_API_TOKEN' // get it from https://web3.storage/
const ipfsService = IPFS.init(token); // init the service
const CID = await ipfsService.storeFiles(path,false); // CID: bafkreicf6eoi7iwh5igmrhcddtnnyh655q3itanzi54qs7zcdialesdsaq
// ipfs.io/ipfs/bafkreicf6eoi7iwh5igmrhcddtnnyh655q3itanzi54qs7zcdialesdsaq

read

Returns the files in the directory with the given CID.

read(cid: CIDString): Promise<Web3File[]>

listUploads

Returns the list of uploads.

listUploads(maxResults: number): Promise<Upload[]>