Skip to main content

Usage

Prerequisites

Signup on storage

Go to Chainsafe Storage if you haven’t created an account already.

Create an API key

  1. Go to settings and click on “Add API key”
  2. This will generate a key and a secret.

NOTE:

Store your secret somewhere safe like you would back up a private key for a crypto wallet. It won’t be displayed again in the API Key List of the settings page.

Storing NFT data

To store NFT data you must provide the following fields:

  • BUCKET_ID as path param
  • path The path where to upload file data. You can provide a non-existing directory path. In that case directories according to the path will be created as well.
  • file The file that you are uploading

Now, let’s upload a file (example_nft) on the path /my_data

POST /api/v1/bucket/<BUCKET_ID>/upload HTTP/1.1
Host: https://api.chainsafe.io
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Authorization: Bearer <API_SECRET>

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="example_nft"
Content-Type: application/json

(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="path"

/my_data
----WebKitFormBoundary7MA4YWxkTrZu0gW

Retrieving NFT data

NFT data stored on ChainSafe Storage can be accessed from the storage download API or from any public IPFS network from any peer that has the content.

Retrieving via download endpoint

Simply provide this path in the json request body.

POST /api/v1/bucket/<BUCKET_ID>/download HTTP/1.1
Host: https://api.chainsafe.io

Authorization: Bearer <API_SECRET>
Content-Type: application/json

{
"path": "/my_data/example_nft"
}

Retrieving via ipfs gateway

First, get the CID of the uploaded file. Then, perform the following request to get file details in json format:

POST /api/v1/bucket/<BUCKET_ID>/file HTTP/1.1
Host: https://api.chainsafe.io
Authorization: Bearer <API_SECRET>
Content-Type: application/json

{
"path": "/my_data/example_nft"
}

Response:

{
"content": {
"name": "file1.pdf",
"cid": "QmfPaBnVAR48UbcjF8crcX7TtJKiV8g3DJkTUsBB6pXb7e",
"size": 10121,
...
},
...
}

Using the CID from above response, data can be fetched directly from any public IPFS gateway. You can also use chainsafe’s IPFS Gateway

The URL should be in this format:

https://{gateway URL}/ipfs/{content ID}/{optional path to resource}

If we want to get our uploaded file through Chainsafe’s IPFS gateway, the URL will be https://ipfs.chainsafe.io/ipfs/QmfPaBnVAR48UbcjF8crcX7TtJKiV8g3DJkTUsBB6pXb7e and there you have it.

You now have everything you need to upload, store and download your NFT’s off-chain data using ChainSafe Storage.