I have a smart contract working on rinkeby which is minting ERC721 tokens. The goal is to allow minting for a week and then to release the metadata and images after a week has passed.
When I deploy it, I use https://gateway.pinata.cloud/ipfs/ as the baseUri that I feed into the contract.
Next, im simulating a delayed metadata/image release:
-
After the tokens are minted, I run a curl POST to add the image to IPFS and get its hash.
-
I then manually pin the image to pinata via UI and create metadata using the pinned image uri.
-
The image link in the metadata resolves in my browser.
-
Next, I run a second curl POST to add the JSON metadata to IPFS.
-
I manually pin the metadata to pinata via UI: https://gateway.pinata.cloud/ipfs/Qmf43nycxRXdwdq3GqT7SKU3MvRyBvbpjzufzZR8ASkMGb
-
At this point, Opensea shows no image and its metadata cannot validate:
The image_url metadata property is failing in validation because ipfs links use a hash and im using the integer token value. I cant see to figure out how to bridge this gap since the hash is generated outside of the contract and it looks like the contract is what is generating this link in the metadata.
Could anyone shine a light on my dilemna? Thank you! 😀
Best Answer
You did not set the TokenURI for NFT, so when NFT gets the URI, BaseURI + TokenID is used.Look at the source code.
It returns the URI: https://gateway.pinata.cloud/ipfs/0
This, of course, is not ideal, the ideal URI should be: https://gateway.pinata.cloud/ipfs/Qmf43nycxRXdwdq3GqT7SKU3MvRyBvbpjzufzZR8ASkMGb
I think you see the reason for the problem here.
The next thing you need to do is call _setTokenUri to store the CID from IPFS so that you can get the correct IPFS link when reading the NFT.
This function is an internal function, and you should provide an external function to use it, but security must be taken care of, or anyone can modify it!