Free decentralized storage and bandwidth for NFTs on IPFS and Filecoin

Srajan Gupta
Blockchain Vidhya
Published in
2 min readSep 8, 2021

A non-fungible token is a unit of data stored on a digital ledger, called a blockchain, that certifies a digital asset to be unique and therefore not interchangeable. NFTs can be used to represent items such as photos, videos, audio, and other types of digital files.

nft.storage is a brand new service in BETA, built specifically for storing off-chain NFT data. Data is stored decentralized on IPFS and Filecoin.

Storing Data

Just upload your data and you’ll receive an IPFS hash of the content (a CID) that can be used in on-chain NFT data as a pointer to the content.

Filecoin provides long-term storage for the data ensuring that even if nft.storage is attacked or taken down the NFT data persists!

Retrieving Data

NFT data stored by nft.storage can be accessed from the decentralized IPFS network from any peer that has the content. CIDs reference immutable content so you can be sure the content you access is the content referenced in the NFT.

The data can be fetched directly in the browser using Brave, or via a public IPFS gateway, or by using IPFS Desktop or the IPFS command line.

Getting Started

Step 1

Register an nft.storage account so that you can create API access keys.

Step 2

Create an API access key and note it down. We will need this API key in Step 3.

Step 3

  1. Create a Node.js project
npm init -y

2. Install the nft.storage npm package

npm install nft.storage --save

3. Create a file named “index.js” inside the project directory and paste the following code:

import { NFTStorage, File } from 'nft.storage'

const apiKey = 'YOUR_API_KEY'
const client = new NFTStorage({ token: apiKey })

const metadata = await client.store({
name: 'Pinpie',
description: 'Pin is not delicious beef!',
image: new File([/* data */], 'pinpie.jpg', { type: 'image/jpg' })
})
console.log(metadata.url)

In the above code snippet for uploading images.

In place of “name”, we need to give a name to our file and in the “image” key, we need to pass the image file path.

Output

ipfs://bafyreib4pff766vhpbxbhjbqqnsh5emeznvujayjj4z2iu533cprgbz23m/metadata.json

--

--