IPFS Network

1. Storage process

Using IPFS Gateway and IPFS remote pinning service, developers can follow below process to upload, store and distribute files:

  1. Upload the file to IPFS gateway, and get the file CID (a unique identifier generated based on the content of each file)

  2. Use CID to call IPFS standard pinning service.

  3. Obtain and monitor pinning status

2. Dependencies

The code sample mainly depends on the following libraries:

Let's Rock 🤟🏻

0. Build web3 authentication header with Crust

This demo only takes Crust(substrate-based chains) as an example, more web3 auth ways can be checked herearrow-up-right.

const { Keyring } = require('@polkadot/keyring');

const seeds = process.argv[2];

// 2. Construct auth header
const keyring = new Keyring();
const pair = keyring.addFromUri(seeds);
const sig = pair.sign(pair.address);
const sigHex = '0x' + Buffer.from(sig).toString('hex');

const authHeader = Buffer.from(`sub-${pair.address}:${sigHex}`).toString('base64');
Copy

1. Upload files to IPFS Gateway

You can get full list of ipfsGateway address herearrow-up-right.

2. Pin file through IPFS Pinning Service

You can get the full list of ipfsPinningService herearrow-up-right.

Will return body like

3. Query on-chain pinning status from IPFS Pinning Service

After pinned success, the demo will return

Last updated