Add Metadata
Last updated
Last updated
Following the previous two tutorials, we created our contract and minted an NFT with ID = 1337. However, our minted NFT has no metadata associated with it. Without metadata, an NFT token is nothing but a token with an ID.
Our smart contract implements the ERC721 meta extension, and it has the following method for getting the metadata URI of an NFT token:
The metadata of an NFT token is presented in a JSON file. Here is an example:
You should create one metadata JSON for each of your NFT tokens. Let's assume you are hosting all the metadata JSON files on the host of my-nft-metadata.com
, and the metadata JSON of each NFT token should have the following format:
After uploading all the metadata JSON files somewhere and hosting them with the same base URI, we can set the base URI of the contract. Again, we can use the cast
command:
Let's verify that our base URI works as expected. We use cast
to get the tokenURI
of the token of 1337
:
You should see the following URI printed out:
Apart from the commonly used fields in the above example, some other fields are also supported in the metadata JSON file. You can find more .
If you upload all your metadata JSON files to IPFS, you should add the whole directory that includes all the JSON files. Then, all the JSON files can be visited with the same base URI. For example, .