Skip to main content

Upload NFT metadata to IPFS

NFT metadata specifies what that data is (image, video, etc.) and the features of the NFT such as the name, description, and any unique features (or traits).

The metadata is stored on a file system outside of the blockchain network, for example, IPFS.

In this tutorial, we'll upload an NFT image and JSON metadata to IPFS. The JSON metadata is used when minting an NFT on the blockchain. The metadata format adheres to the standards required by NFT marketplaces such as OpenSea.

info

This tutorial uploads data to IPFS using the IPFS API. Infura also allows you to upload content using the Infura UI or using ipfs-upload-client.

Prerequisites

Steps

1. Create a dedicated gateway

Infura IPFS projects allow you to use a public gateway, or dedicated gateway, to access content. Public gateways will be deprecated, so we've used a dedicated gateway in this tutorial.

If you do not already have a dedicated gateway, go to your IPFS project settings and enable dedicated gateways. In this example, we'll use the subdomain name meme-nft.

2. Upload the image file

First we'll upload the NFT image from your local drive to IPFS. Ensure you replace <API-Key> and <API-Key-Secret> with your Infura IPFS details.

info

Download the image and name it meme-nft.jpeg as in the example below. Alternatively, upload an image of your choice.

If not running this request in the same directory as your image, ensure you update the file location in -F file=@"<File-location>".

curl "https://ipfs.infura.io:5001/api/v0/add" \
-X POST \
-F file=@"meme-nft.jpeg" \
-u "<API-Key>:<API-Key-Secret>"

View the image using the hash provided in the response.

For example, https://meme-nft.infura-ipfs.io/ipfs/QmW5sPVbZDueZwvSuibteAwDFwFXhF8gebfptGBx1DZq1j, or use an IPFS browser.

3. Create the JSON metadata file

We'll now create the JSON metadata file that links to the image on IPFS, and stores the properties of the NFT. You can use the ipfs-upload-client to upload the JSON file, or use the IPFS API methods as used in this tutorial.

In this example, we'll create meme-nft.json with the following contents:

{
"name": "Meme NFT",
"description": "NFTs are so hot right now",
"image": "https://meme-nft.infura-ipfs.io/ipfs/QmW5sPVbZDueZwvSuibteAwDFwFXhF8gebfptGBx1DZq1j",
"attributes": [
{ "trait_type": "meme", "value": "So Hot Right Now" },
{ "trait_type": "event", "value": "EthDenver 2022" }
]
}

4. Upload the metadata file

Upload the metadata file to IPFS.

danger

Save the IPFS JSON metadata location after successfully uploading it, because we'll need this when minting the NFT.

curl "https://ipfs.infura.io:5001/api/v0/add" \
-X POST \
-F file=@"meme-nft.json" \
-u "<API-Key>:<API-Key-Secret>"

View the image using the hash provided in the response.

For example, https://meme-nft.infura-ipfs.io/ipfs/QmfF7Y4FEsPKpRc7z7Mc2Gub2DxNM58zAAq5JYTcNVqjU5, or use an IPFS browser.

Next, we'll deploy the NFT smart contract on the Ethereum blockchain.