1

I created an ERC721 contract and deploy it on the Goerli testnet.

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract TestNFT is ERC721URIStorage, Ownable {
    uint256 totalMinted = 0;

    constructor() ERC721("MyNFT", "MNFT") {}

    function mint(address to) public {
        _mint(to, totalMinted);
        totalMinted++;
    }

    function mintWithData(address to, string memory tokenURI) public {
        _mint(to, totalMinted);
        _setTokenURI(totalMinted, tokenURI);
        totalMinted++;
    }

    function setTokenURI(uint256 tokenId, string memory tokenURI)
        public
        onlyOwner
    {
        _setTokenURI(tokenId, tokenURI);
    }
}

It has 3 functions mint, mintWithData and setTokenURI. Opensea can just show NFT with the function mintWithData. This function have 2 function _mint and _setTokennURI.

I manually minted NFT and set token URI with 2 functions mint and setTokenURI. But it just shows an NFT without any metadata.

Can anyone tell me why this occurs? I used the same function with mintWithData but it can't work.

1 Answer 1

0

About the tokenURI that you are passing as an argument to setTokenURI - does the link you provide lead to a json object, that is already uploaded to IPFS ?

Also, it depends on how you have set up the .json file that contains the metadata of the NFT. See an example:

{
    "name":"Luigi",
    "description":"The sigma brother of Mario",
    "image":"https://ipfs.io/ipfs/QmWhFZLWPbWD7oMzkWvdxoD2rBrwaaca1SnyRitDPQCCLx",
    "attributes":[
        {
            "trait_type":"Strength",
            "value":5,
            "max_value":10
        },
        {
            "trait_type":"Speed",
            "value":10,
            "max_value":10
        },
        {
            "trait_type":"Stamina",
            "value":8,
            "max_value":10
        },
        {
            "trait_type":"Damage",
            "value":10,
            "max_value":10
        },
        {
        "display_type":"boost_number",
        "trait_type":"Jump",
        "value":1
        },
        {
            "trait_type":"Jump",
            "value":10,
            "max_value":10
        },
        {
            "display_type":"boost_percentage",
            "trait_type":"Speed",
            "value":20
        },
        {
            "display_type":"number",
            "trait_type":"Generation",
            "value":1
        },
        {
            "trait_type":"Humble",
            "value":"True"
        },
        {
            "trait_type":"Brave",
            "value":"True"
        }

    ]

}

And this is how the NFT looks on OS :

https://testnets.opensea.io/assets/mumbai/0xb1ba9c7fd7c2269f2e7f86077e1c8988ae3737f7/1

I hope you got the idea. Please share whether this has solved your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.