How to provide metadata for ERC721

Actually I do have another question (Deployment failed on Rinkeby: “ERC721PresetMinterPauserAutoId” hit an invalid opcode). How do I provide the metadata you mentioned. The uri is pointing to a diretory but I cant see a file name. So Im not sure how to proceed.

for exemple is pointing to what exactly? the metadata but how does it get passed. My test consisted on using PHP to return data.
So my URI would be a get param left empty like;

I tried

Then by running the query the 0 would fill it but it doesnt work that way I think.

1 Like

Or would it be more effective to use IPFS?


Hi @madeindreams,

I have moved this question to a new topic. I recommend creating a new topic per question as it makes it easier for community members to answer, (and for future readers to find answers).

With the EIP-721 optional metadata extension, each tokenID can have a tokenURI which points to a JSON file with name, description and image for the given token ID.

Some example metadata which is just JSON:

For testing purposes you could do what I did and use to point to a single file in a GitHub repository to use for your token metadata. You could then move to your own server for further testing.

My data file is here:

You can view my NFT on OpenSea:

Using the preset ERC721PresetMinterPauserAutoId we get lower cost minting as we only need to store a single baseURI and then when we look up the tokenURI for each token we concatenate the baseURI and the tokenID (as a string) together.

In your example you would need your baseURI to be and then the tokenURI for tokenID would be and this should return the JSON metadata for tokenID 0.

Instead of centralized metadata (that you could change at any time) you could use IPFS.

There would be increased minting costs as you would need to store the IPFS hash for each tokenID but it would be more decentralized.

If I recall correctly OpenSea supports providing an IPFS hash for metadata.


Hi @madeindreams,

Did you need more information or did the above reply answer your question? (You can mark it as the solution if it did).

Feel free to ask all the questions that you need.

2 posts were split to a new topic: ERC721 metadata not showing on OpenSea

Great explanation! There’s a typo in the last paragraph:

to store the IPFS has

should be:

to store the IPFS hash

1 Like

Hi @Cryptokkie,

Thanks, fixed. :pray:

1 Like

A post was split to a new topic: JSON from PHP not displayed on OpenSea

[SOLVED] Hey @abcoathup, I have to hijack this post (sorry :innocent:). How did you managed to make your contract appearing as "My NFT" in OpenSea? We have an issue with ERC1155, that these contracts will be displayed as "Unidentified Contract". Is there anything that you did additionally in order to help OpenSea to understand the contract much better?

UPDATE: this is already solved Unidentified contract: OpenSea is unable to "understand" ERC-1155 - #2 by itinance

What would the order of events be for storing the IPFS hash for each tokenId?

Something like:

  1. Make hash for every token
  2. mint(tokenId, hash)? Where we set the baseURI of that tokenId to that hash?

I suppose what hangs me up is that that would mean that the tokenId isn't stored with the metadata on IPFS correct?

You will not use baseURI for dynamically minted token sets, which utilize ipfs. If each metadata you're pointing to has nonidentical content, each token will have a unique ipfs hash, i.e., the full URI is ipfs://<content hash> with no tokenId path parameter appended at the end (there's a way to make one with ipfs folders, but it won't solve your base uri problem). So again, each tokenURI call will return a content generated hash mapped per tokenId but that id won't be interpolated into the URI. At best, you can use baseURI = "ipfs://" to at least provide the redundant protocol prefix.