Complete Your Web3 Journey with Decentralized Storage

640,037 TB

Storage capacity

1,525

DISTRIBUTED NODES

2,021,065

STORAGE ORDERS

32

REPLICAS ON AVERAGE

A tech stack to be built upon

Your omnichain solution for decentralized storage in web3

IPFS

  • Native IPFS integrations and toolkits for all web3 and web2 users
  • Chain agnostic storage services for any use case scenario
  • Leverage Crust solutions to enhance your IPFS experience.
Start Building

    Api Code

const got = require('got');
const { create, globSource } = require('ipfs-http-client');
const { Keyring } = require('@polkadot/keyring');

function timeout(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

async function main() {
    // 1. Get all inputss
    const path = './build';
    const seeds = process.argv[2];
    const ipfsGateway = 'https://crustwebsites.net'; // IPFS Web3 Authed Gateway address
    const ipfsPinningService = 'https://pin.crustcode.com/psa'; // IPFS Web3 Authed Pinning Service address

    // 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');

    // 3. Create ipfs http client
    const ipfs = create({
        url: ipfsGateway + '/api/v0',
        headers: {
            authorization: 'Basic ' + authHeader
        }
    });

    const { cid } = await ipfs.add(globSource(path, '**/*'));

    if (cid) {
        console.log(cid.toV0().toString());
    } else {
        throw new Error('IPFS add failed, please try again.');
    }

    // 4. Pin to crust with IPFS standard W3Authed pinning service
    const {body} = await got.post(
        ipfsPinningService + '/pins',
        {
            headers: {
                authorization: 'Bearer ' + authHeader
            },
            json: {
                cid: cid.toV0().toString(),
                name: 'crust-demo'
            }
        }
    );

    if (body) {
        const rid = JSON.parse(body)['requestId'];
        console.log(body, rid);
        // 5. Query pinning status through pinning service
        while (true) {
            const {body: pinningStat} = await got(
                ipfsPinningService + `/pins/${rid}`,
                {
                    headers: {
                        authorization: 'Bearer ' + authHeader
                    }
                }
            );
            console.log(pinningStat); // After success, you can query the cid on Crust

            await timeout(1000);
        }
    } else {
        console.log(body);
        throw new Error('Crust pin failed, please try again.');
    }
}

main().catch(error => {
    console.error(error.message);
});

IPFS Done the Right Way

Elevating your IPFS experience, Crust Network serves as incentivized service layer, safeguarding your data with accessibility, replication, and long-term guarantees.

Dedicated Gateway Service:

Upload and retrieve data with Crust’s dedicated IPFS gateways. Our gateways ensure highest performance for the best user experience on IPFS.

Decentralized Pinning Service:

Pin your data to Crust and enjoy multiple replicas per file secured via a fully decentralized protocol and infrastructure. On-demand as well as permanently.

Data Query Service:

Inspect your storage orders directly on-chain or via our IPFS storage explorer to validate data availability, number of replicas and more.

Products

Get in touch with the team