0

I deployed a simple NFT contract based on the nibbstack ERC721 implementation

For testing purposes I hardcoded the ipfs link into the contract. The mint function looks like this, for testing purposes everyone who send 100 Wei can get an NFT

function mint() public payable {
         require(msg.value == 100, "Send 100 Wei");
         super._mint(msg.sender, tokenId);
         super._setTokenUri(tokenId, nfts[0]);
         tokenId++;
    }

The ipfs are hardcoded like this:

string[] nfts = ["https://ipfs.io/ipfs/QmUFbUjAifv9GwJo7ufTB5sccnrNqELhDMafoEmZdPPng7"];

the ipfs link points to a json file that looks like this (I picked it from the ipfs documentation):

{
    "name": "NFT Art",
    "description": "This image shows the true nature of NFT.",
    "image": "https://ipfs.io/ipfs/QmQEVVLJUR1WLN15S49rzDJsSP7za9DxeqpUzWuG4aondg",
}

However, format must be wrong, I can never view the image. Here is the opensea site for an example deployment on the Goerli testnet:

enter image description here

2 Answers 2

0

Checkout the ERC721 Metadata JSON Schema from the ERC721 token standard

0

You didn't add tokenURI(tokenId) nor _baseURI() functions.

If you are using smart contract libs like @openzeppelin, you will find that this function tokenURI(tokenId) returns a URL of the NFT of the given tokenId.

You need to modify (override) it to return the link for the NFT, I will leave an example.

string constant TOKEN_URI = "https://ipfs.io/ipfs/QmUFbUjAifv9GwJo7ufTB5sccnrNqELhDMafoEmZdPPng7";

function tokenURI(uint256 /* tokenId */) public pure override returns (string memory) {
    return TOKEN_URI;
}

This is just a simple demo, you can use the tokenId that is passed as a parameter to the function to return different URLs for different NFTs.

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.