nft – Understanding NFT Token Metadata and URI in ERC-1155

contracturierc-1155ipfsnft

I want to develop a user interface which accepts an image file from the user, and a ERC1155 smart contract capable of minting tokens backed by the uploaded image. In other words, I need my ERC1155 tokens to represent a specific image. However, there are some obscurities for me regarding this topic:

  • What is Token URI? What are its use cases? What does it offer to users?
  • What is Token Metadata? Is it different from Token URI?
  • What are our options if we want to host our token URI somewhere? Is it necessary to host the URI on a decentralized storage such as IPFS? What happens if we keep the URI on the smart contract?
  • Why are there third party services ( like Infura and NFT.storage ) for establishing connection to IPFS to upload the NFT image. I mean why we cannot directly get connected to the IPFS?

Thanks in advance for the clarification

Best Answer

So tokenURI() is the function that will return the address where the metadata of this specific token is stored.

The metadata is a .json file (following the ERC721Metadata standard) where all the data associated to the NFT is stored. Such as its name, the address where the image is stored...

https://eips.ethereum.org/EIPS/eip-721

Here is a detailed explanation of ERC721 metadata schemas: https://nftschool.dev/reference/metadata-schemas/#ethereum-and-evm-compatible-chains

enter image description here

If you want your NFT to have a metadata and an image linked to your NFT it is much better (and the standard way used by applications) to store them offChain, since doing it onChain would cost a lot.

Your options to store your metadata as of now are either on a server (centralized) or on IPFS which is a decentralized storage. IPFS stands for Interplanetary File System.

https://en.wikipedia.org/wiki/InterPlanetary_File_System

https://github.com/ipfs/ipfs

The third party services are here to make your life easier. Originally you would have to run an IPFS node yourself to store and access the data you want. Third parties allow you to store on already existing nodes.

PS: All those answers are easily accessible on stackoverflow or the internet. It's always better to search by yourself first ;)