YourNewEmpire
YourNewEmpire

Reputation: 153

OpenSea IPFS Metadata

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";
    }
}

Upvotes: 5

Views: 6919

Answers (3)

Patrick Collins
Patrick Collins

Reputation: 6131

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:

  • One with the image
  • One with the metadata.json which contains the URI from the image

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

And then how it renders on OpenSea.

More information on deploying and listing on opensea.

Upvotes: 13

GreyMatters
GreyMatters

Reputation: 1

FWIW - I had the same issue on openseas. Works with the URI of BOTH:

  1. JSON ends in .JSON
  2. IMAGE file ends in .PNG

Upvotes: 0

fedeb
fedeb

Reputation: 162

as of my understanding (still haven't done it), the tokenURI has to return an URL that points yo uto the metadata, that metadata containing the actual IPFS url. Take this with a grain of salt

Upvotes: 0

Related Questions