I’m working on an ERC721 smart contract that should mint NFTs with predefined metadata when users pay 100 Wei. The contract compiles and deploys fine, but the metadata isn’t showing up correctly on OpenSea testnet.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
contract SimpleNFT is ERC721URIStorage {
uint256 private currentTokenId = 1;
string private metadataURI = "https://ipfs.io/ipfs/bafkreiabcdef123456789/metadata.json";
constructor() ERC721("SimpleNFT", "SNFT") {}
function createToken() external payable {
require(msg.value >= 100 wei, "Payment of 100 wei required");
_safeMint(msg.sender, currentTokenId);
_setTokenURI(currentTokenId, metadataURI);
currentTokenId++;
}
}
The JSON metadata file contains:
{
"name": "Mystery Token",
"description": "A simple test NFT with basic properties",
"image": "ipfs://bafkreixyz987654321/mystery-image.png"
}
When I test this same metadata URI with standard minting functions it works perfectly. However, in my custom contract the image and metadata don’t appear on marketplaces. I’ve deployed to Goerli testnet but the NFTs show as blank. What could be causing this metadata issue?
hmm this is interesting - i’ve been messing with erc721 contracts lately and saw similar weird stuff with metadata display. what jumps out is you’re using the same metadataURI for every token. opensea and other marketplaces probably get confused since they expect unique metadata per nft.
have you tried calling tokenURI() directly on your contract? check through etherscan or remix to see if it’s returning the right uri for specific token ids. sometimes it’s not ipfs - it’s how the contract handles uri storage.
also what do you mean “standard minting functions work perfectly” with the same metadata uri? comparing to a different contract or just testing the ipfs link in browser?
one more thing - is your ipfs metadata actually accessible? the gateway might be slow or content not pinned properly. try that bafkreiabcdef123456789 hash through different gateways like gateway.pinata.cloud or cloudflare-ipfs.com.
what’s the transaction look like on etherscan when you mint? does tokenURI get set right in the logs?
hold up - that IPFS hash looks fake. bafkreiabcdef123456789 screams placeholder text to me lol. and 100 wei for gas? that’s way too low and will probably break your transaction. run your metadata through jsonlint first before you assume the contract’s bugged
Had the exact same issue with my NFT contract - super frustrating! Your problem is probably that all tokens are pointing to the same metadata URI, which messes up marketplaces when they try to grab unique data for each NFT. Each token needs its own metadata file on IPFS. Set up dynamic metadata URIs in your contract. I structure mine as metadata/{tokenId}.json - keeps everything unique. Also check if your IPFS gateway is working properly since outages cause these problems all the time. And heads up - OpenSea usually needs a manual refresh after minting, so don’t panic if changes don’t show up right away.