I’m facing an issue with my ERC1155 smart contract where the NFT images fail to appear on the OpenSea testnet. I suspect there might be a problem with how I’ve set the metadata URI, but I’m unable to identify the specific error.
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract GameItems is ERC1155, Ownable {
uint256 public constant SWORD = 0;
uint256 public constant SHIELD = 1;
constructor() ERC1155("https://ipfs.io/ipfs/{id}.json") {
_mint(msg.sender, SWORD, 1, "");
_mint(msg.sender, SHIELD, 3, "");
}
function createItem(address player, uint256 tokenId, uint256 quantity) public onlyOwner {
_mint(player, tokenId, quantity, "");
}
function destroyItem(address player, uint256 tokenId, uint256 quantity) public {
require(msg.sender == player);
_burn(player, tokenId, quantity);
}
}
Here are my JSON metadata files:
{
"image": "ipfs://bafybeienrrxym2d3b5u7glcvdrz63rztxkue7p4bly4fcsma55nupmxsvy",
"description": "A sharp blade for warriors",
"name": "Magic Sword"
}
{
"image": "ipfs://bafybeieh4lcllyimopk6pmacjyx4atgdqsywvsia6nuuq6niucdqxwbq5i",
"description": "Protective gear for battle",
"name": "Steel Shield"
}
I think the root of the problem lies in my URI reference, but I’m unsure how to correct it. Any suggestions on what could be causing this?
Hmm, interesting issue! I’ve hit something similar with my own NFT project. Quick question - are you sure those IPFS hashes point to your JSON files and not the images?
Your URI structure https://ipfs.io/ipfs/{id}.json looks right, but OpenSea’s picky about metadata formatting. Have you tried accessing those URLs directly? Go to https://ipfs.io/ipfs/0.json and see if it returns your sword metadata.
Also - did you upload your JSON files with exactly “0.json” and “1.json” names? That’s what your contract expects with the {id} placeholder. People sometimes upload JSONs with different names then wonder why nothing shows up lol.
One more thing - OpenSea testnet’s slow to refresh metadata sometimes. Have you tried the “refresh metadata” button or is it not picking anything up at all? Would help to know if you’re seeing blank placeholders or if the NFTs aren’t showing up entirely!
Your JSON metadata’s missing some fields OpenSea needs. Add “attributes”: and “external_url”: “” to both metadata files. Also make sure your IPFS files are actually named 0.json and 1.json - that’s what the {id} placeholder looks for.
Hit this exact issue last month with my ERC1155 project. Your metadata URI structure is the problem. You’re using https://ipfs.io/ipfs/{id}.json but your IPFS hash should point to a folder with numbered JSON files, not individual files. Upload your JSON files (0.json and 1.json) to one IPFS folder, then use that folder’s hash in your constructor. Should look like https://ipfs.io/ipfs/QmYourFolderHash/{id}.json. Right now your contract’s trying to append the token ID to a direct file hash, which creates broken URLs. Made the same mistake and wasted hours debugging. Fixed my IPFS uploads and OpenSea worked within minutes.