Pinning with crustnetwork

Overview

1. Storage process

  1. Put file to IPFS (local IPFS or IPFS gateway), get CID and FileSize back

  2. Send place storage order transaction to Crust with CID and FileSize

  3. Query order status by CID

2. Dependencies

The code sample mainly depends on the following libraries:

Let's Rock 🤟🏻

1. Upload file to IPFS

If you want to learn how to upload FOLDERS/FILES into IPFS, please refer this STEParrow-up-right

First, you need to put your file into IPFS, there's 2 ways to upload file to IPFS: local IPFS node or remote IPFS gateway:

  • With local IPFS node

You can find more ipfsW3GW endpoints on LINKarrow-up-right. Greatly improve the speed of ipfsW3GW by configuring Meson CDNarrow-up-right.

You can also find more authHeader web3 supports on LINKarrow-up-right, the following example just takes ethereum as example.

2. Upload folder

For folder upload, refer to this linkarrow-up-right to build. It is recommended to use this gateway: https://gw.crustfiles.app, or build a local IPFS node with a good network for uploading. At the same time, during the upload process, you can record the cids value of the file in the folder or call the IPFS command to obtain the cids value contained in the folder after the upload is completed. The code is as follows:

In addition, after Place storage order, you can use the folder-analyzer service to obtain directly, see the 4 section for details.

3. Place storage order

Next, we need to send a transaction named Place Storage Order on Crust chain, this transaction will dispatch your storage requirement to each Crust IPFS nodes through blockchain. Then the IPFS nodes will start pulling your file with IPFS protocol.

You can find more crustChainEndpoint on LINKarrow-up-right.

You can create your own account(seeds) on LINKarrow-up-right.

If it's a folder, please set memo = 'folder'

4. Folder information

If you store a folder in Crust. Through the folder analyzer servicearrow-up-right, you can obtain relevant information about the folder you placed the order in. There is a certain delay in updating this information, which is determined by the network environment.

4.1 Get the cids value contained in the folder

  • request

  • result:

4.2 Get the root of the folder to which the cid belongs

  • request

  • result:

Additional information such as the number of copies can be obtained on the crust chain by using the root cid of the folder

5. Query order status

Then, you can query the order status{replica_count, storage_duration, ...} by calling on-chain status.

And it'll return:

6. Add file assurance

The default storage time for a single transaction(order) is 6 months. If you want to extend the storage duration, Crust provides an assurance pool for you to customize the file's storage time, it allows you to put some tokens and will automatically extend the file's storage time.

Last updated