简体   繁体   English

OpenSea IPFS 元数据

[英]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.我一直在使用指向我的 ipfs hash ipfs://QmeB87321i121xN88bXZzmjSUXqS46B8bU3H9ocyTb8tJf 的链接作为基本令牌 URI 测试我的 erc-721 合同。 So the contracts are deployed and the items have been minted by me, but opensea cant read that metadata uri as expected.因此,合同已部署并且项目已由我铸造,但 opensea 无法按预期读取该元数据 uri。 The documentation on opensea suggests that it should be sufficent. opensea 上的文档表明它应该足够了。

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.您需要指向元数据文件,而不是指向在 IPFS 中包含文件的文件夹。

A Metadata file is a json formatted file that has information about the tokenId.元数据文件是一个json格式的文件,其中包含有关 tokenId 的信息。 You'd place your image URI in the image section.您将图像 URI 放在image部分。 Here is an example:这是一个例子:

{
    "name": "You NFT token name",
    "description": "Something Cool here",
    "image": "https://ipfs.io/ipfs/QmTgqnhFBMkfT9s8PHKcdXBn1f5bG3Q5hmBaR4U6hoTvb1?filename=Chainlink_Elf.png",
    "attributes": []
}

So on IPFS you'd have 2 files:所以在 IPFS 上你会有 2 个文件:

  • One with the image一张有图
  • One with the metadata.json which contains the URI from the image一个包含来自图像的 URI 的 metadata.json

Then, in your contract, you'll have to call the _setTokenURI(tokenId, _tokenURI);然后,在您的合同中,您必须调用_setTokenURI(tokenId, _tokenURI); function (imported by the openzepplin erc721 package) function(openzepplin erc721包导入)

_setTokenURI(tokenId, _tokenURI);

The _tokenURI should be your metadata URL/URI. _tokenURI应该是您的元数据 URL/URI。 And the tokenId is the id of your NFT. tokenId 是你的 NFT 的 id。

Here is an example TokenURI in IPFS 这是 IPFS 中的示例 TokenURI

And then how it renders on OpenSea. 然后是它如何在 OpenSea 上呈现。

More information on deploying and listing on opensea. 有关在 opensea 上部署和上市的更多信息。

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.据我了解(仍未完成),tokenURI 必须返回一个 URL 指向元数据,该元数据包含实际的 IPFS url。 Take this with a grain of salt把这个和一粒盐一起吃

FWIW - I had the same issue on openseas. FWIW - 我在公海上遇到了同样的问题。 Works with the URI of BOTH:适用于两者的 URI:

  1. JSON ends in.JSON JSON 结束于.JSON
  2. IMAGE file ends in.PNG IMAGE 文件以.PNG 结尾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM