Solidity – Fix NFT Picture and Metadata Display Issues on Testnet OpenSea (Polygon Mumbai)

openseapolygonsolidity

The minted NFT item and detail not displayed on test net Opensea while rinkeby network working properly . pls kindly advise where gone wrong

https://testnets.opensea.io/collection/squirrel-eqf09pjm5s

https://mumbai.polygonscan.com/address/0xEE21cF8F15e487968706C5bbD15837c50D1aB2a1

contract.sol

constructor() ERC721("Squirrel", "SRL") {
    
    _baseTokenURI = "QmSrH7nkakj9T7FUKSD48ENcJusvnaTdmdJV9AXhLPHNst/";  //metadata url

the ipfs metadata and images file working fine.

json = ipfs/QmSrH7nkakj9T7FUKSD48ENcJusvnaTdmdJV9AXhLPHNst/0

{"name": "Squirrel #0", "description": "Squirrel NFT . limited edition 1,000!", "image": "ipfs://QmczVxRT66QqC7HeYh6ZnT8QLd2qoAiqW8DfhX4ghG7bVw/0.png", "attributes": [{"trait_type": "Background", "value": "blue"}, {"trait_type": "Body", "value": "maroon"}, {"trait_type": "Eyes", "value": "standard"}, {"trait_type": "Clothes", "value": "blue_dot"}, {"trait_type": "Held Item", "value": "nut"}]}

images :

ipfs.io/ipfs/QmczVxRT66QqC7HeYh6ZnT8QLd2qoAiqW8DfhX4ghG7bVw/0.png

Best Answer

Let us first understand how Opensea reads your contract to retrieve the meta-data –

From Opensea's documentation

To find this URI, we use the tokenURI method in ERC721 and the uri method in ERC1155. First, let's look closely at the tokenURI method in the Creature contract.

Further:

The tokenURI function in your ERC721 or the uri function in your ERC1155 contract should return an HTTP or IPFS URL, such as https://opensea-creatures-api.herokuapp.com/api/creature/3. When queried, this URL should in turn return a JSON blob of data with the metadata for your token. You can see an example of a simple Python server for serving metadata in the OpenSea creatures repo here.

Further for IPFS specific

If you use IPFS to host your metadata, your URL should be in the format ipfs://. For example, ipfs://QmTy8w65yBXgyfG2ZBg5TrfB2hPjrDQH3RCQFJGkARStJb

Now let us see what your contract returns the tokenURI for a minted token (in this case, tokenID: 0)

enter image description here

As you can see, your contract is returning QmSrH7nkakj9T7FUKSD48ENcJusvnaTdmdJV9AXhLPHNst/0 which is incomplete since it does not contain a base (ipfs://) to resolve from.

Your tokenURI method should return the complete resolvable IPFS URI to your JSON file: ipfs://QmczVxRT66QqC7HeYh6ZnT8QLd2qoAiqW8DfhX4ghG7bVw/0

Additionally, you should make sure your JSON file is query-ready by manually visiting the IPFS URL through any IPFS enabled browser.

Here's an example of doodle contract returning URI:

Doodle's contract returning tokenURI for tokenID 0

Related Topic