I’m developing an ERC1155 contract for NFTs, but I’m facing issues with the metadata not displaying correctly on the OpenSea testnet. The images are not appearing properly despite having the necessary JSON files prepared.
Below is my smart contract code:
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract UniqueNFTCollection is ERC1155, Ownable {
uint256 public constant CACTUS = 0;
uint256 public constant BANYA = 1;
constructor() ERC1155("http://ipfs.io/ipfs/{id}.json") {
_mint(msg.sender, CACTUS, 1, "");
_mint(msg.sender, BANYA, 2, "");
}
function mintNFT(address to, uint256 id, uint256 amount) public onlyOwner {
_mint(to, id, amount, "");
}
function burnNFT(address account, uint256 id, uint256 amount) public {
require(msg.sender == account);
_burn(account, id, amount);
}
}
My JSON metadata files are as follows:
{
"image": "ipfs://bafybeienrrxym2d3b5u7glcvdrz63rztxkue7p4bly4fcsma55nupmxsvy",
"description": "My first plant",
"name": "Cactus Arcadiy"
}
{
"image": "ipfs://bafybeieh4lcllyimopk6pmacjyx4atgdqsywvsia6nuuq6niucdqxwbq5i",
"description": "GoodZone is a banya with pool",
"name": "Banya"
}
I feel there might be something off with the image references in the JSON files, yet I can’t identify the problem. Any suggestions on resolving the issue with loading the metadata?
Hmm, interesting - I’ve hit similar issues with ERC1155 metadata display. Your constructor URI pattern caught my eye… is OpenSea actually substituting the {id}
placeholder correctly?
When you say images aren’t appearing properly, do you mean the metadata won’t load at all, or it loads but the images in the JSON don’t display? These are different problems.
Quick question - did you actually upload JSON files to IPFS with filenames “0.json” and “1.json”? Your contract expects http://ipfs.io/ipfs/0.json
and http://ipfs.io/ipfs/1.json
based on your constructor, but you haven’t mentioned the actual IPFS hashes for the metadata files.
Also, have you tried accessing your metadata URLs directly in a browser? Sometimes the files just aren’t where the contract thinks they are.
What does OpenSea actually show for your NFTs? “Failed to load metadata” or does it load the name/description but skip the image?
Your constructor’s URI pattern has a major problem. You’re using http://ipfs.io/ipfs/{id}.json
but assuming the metadata files actually exist at those paths. Sounds like you haven’t uploaded your JSON files to IPFS yet - you just have the content ready. You need to upload each JSON file to IPFS first and grab their specific hashes. Then either update your constructor URI to point to a folder containing 0.json and 1.json, or write a custom uri()
function that returns the exact IPFS hash for each token ID. I ran into this same issue before. Mapping token IDs directly to their metadata URIs works way better than hoping OpenSea will handle the {id} placeholder correctly.
your ipfs links are probably the problem. use https://ipfs.io/ipfs/
instead of ipfs://
in your json metadata - opensea often can’t resolve the ipfs:// protocol directly. also make sure your json files are actually uploaded where your contract thinks they are.