I have been testing my erc-721 contract with a link to my ipfs hash ipfs://QmeB87321i121xN88bXZzmjSUXqS46B8bU3H9ocyTb8tJf
as the base token URI. The contracts are deployed and the items have been minted by me, but OpenSea can't read that metadata uri as expected. The documentation on OpenSea suggests that it should be sufficient.
My Contract
pragma solidity ^0.5.0;
import "./ERC721Tradable.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract Creature is ERC721Tradable {
constructor(address _proxyRegistryAddress)
public
ERC721Tradable("StygianCoins", "STG", _proxyRegistryAddress)
{}
function baseTokenURI() public pure returns (string memory) {
return "https://ipfs.io/ipfs/QmeB87321i121xN88bXZzmjSUXqS46B8bU3H9ocyTb8tJf";
}
function contractURI() public pure returns (string memory) {
return "https://contract-abis.herokuapp.com/api/contract/stygian-coins";
}
}
Instead of pointing to your folder that has your files in IPFS, you'll need to point to a metadata file.
A Metadata file is a json
formatted file that has information about the tokenId. You'd place your image URI in the image
section. Here is an example:
{
"name": "You NFT token name",
"description": "Something Cool here",
"image": "ipfs://QmTgqnhFBMkfT9s8PHKcdXBn1f5bG3Q5hmBaR4U6hoTvb1?filename=Chainlink_Elf.png",
"attributes": []
}
So on IPFS you'd have 2 files:
Then, in your contract, you'll have to call the _setTokenURI(tokenId, _tokenURI);
function (imported by the openzepplin erc721 package)
_setTokenURI(tokenId, _tokenURI);
The _tokenURI
should be your metadata URL/URI. And the tokenId is the id of your NFT.
Here is an example TokenURI in IPFS