我一直在测试我的 erc-721 契约(Contract),其中包含指向我的 ipfs 哈希 ipfs://QmeB87321i121xN88bXZzmjSUXqS46B8bU3H9ocyTb8tJf
的链接作为基本 token URI。契约(Contract)已部署,项目已由我类型转换,但 OpenSea 无法按预期读取元数据 uri。 OpenSea 上的文档表明它应该足够了。
我的契约(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";
}
}
最佳答案
您需要指向元数据文件,而不是指向在 IPFS 中包含文件的文件夹。
元数据文件是 json
包含有关 tokenId 信息的格式化文件。您将图像 URI 放在 image
中部分。这是一个例子:
{
"name": "You NFT token name",
"description": "Something Cool here",
"image": "ipfs://QmTgqnhFBMkfT9s8PHKcdXBn1f5bG3Q5hmBaR4U6hoTvb1?filename=Chainlink_Elf.png",
"attributes": []
}
所以在 IPFS 上你会有 2 个文件:然后,在您的契约(Contract)中,您必须调用
_setTokenURI(tokenId, _tokenURI);
函数(由 openzepplin erc721 包导入)_setTokenURI(tokenId, _tokenURI);
_tokenURI
应该是您的元数据 URL/URI。 tokenId 是你的 NFT 的 id。Here is an example TokenURI in IPFS
And then how it renders on OpenSea.
More information on deploying and listing on opensea.
关于solidity - OpenSea IPFS 元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66602944/