我正在尝试为OpenSea上的NFT集合实现OpenSea,但是,如果使用下面的代码,契约的元数据将不会在OpenSea集合的页面上更新,也不会更新令牌页面上的契约描述。
TokenURI也存储在链上,并在给定适当的数据时进行更新.在我的例子中,它将是一个SVG映像以及一些字符串以获取信息。(更详细的代码片段)
代码丢失了所有与此无关的内容。
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "./base64.sol";
contract Test is ERC721Enumerable, ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
using Strings for uint256;
string private _contractURI;
constructor() ERC721("Test", "T") {}
function svgToImageURI(string memory _source) public pure returns (string memory) {
string memory baseURL = "data:image/svg+xml;base64,";
string memory svgBase64Encoded = Base64.encode(bytes(string(abi.encodePacked(_source))));
return string(abi.encodePacked(baseURL, svgBase64Encoded));
}
function formatTokenURI(string memory _imageURI, string memory _name, string memory _description, string memory _properties) public pure returns (string memory) {
return string(
abi.encodePacked(
"data:application/json;base64,",
Base64.encode(
bytes(
abi.encodePacked(
'{"name":"', _name,
'", "description": "', _description, '"',
', "attributes": ', _properties,
', "image":"', _imageURI, '"}'
)
)
)
)
);
}
function setTokenURI(uint256 _tokenId, string memory _tokenURI) public onlyOwner() {
_setTokenURI(_tokenId, _tokenURI);
emit tokenChanged(_tokenId);
}
function setContractURI(string memory contractURI_) public onlyOwner() {
_contractURI = string(abi.encodePacked(
"data:application/json;base64,",
Base64.encode(
bytes(
abi.encodePacked(
contractURI_
)
)
)
));
}
function contractURI() public view returns (string memory) {
return _contractURI;
}
}我提供给setContractURI函数的输入是来自OpenSea网站的一个简单的JSON片段,因此我确信我遵守了它的规则。
{
"name": "OpenSea Creatures",
"description": "OpenSea Creatures are adorable aquatic beings primarily for demonstrating what can be done using the OpenSea platform. Adopt one today to try out all the OpenSea buying, selling, and bidding feature set.",
"image": "https://openseacreatures.io/image.png",
"external_link": "https://openseacreatures.io",
"seller_fee_basis_points": 100,
"fee_recipient": "0xA97F337c39cccE66adfeCB2BF99C1DdC54C2D721"
}我做错了什么?我在波利贡孟买测试网上。
发布于 2021-10-03 09:08:59
我的setContractURI函数似乎有一个encodepacket太多了。看起来它现在正在OpenSea上工作。
function setContractURI(string memory contractURI_) public onlyOwner() {
_contractURI = string(abi.encodePacked(
"data:application/json;base64,",
Base64.encode(
bytes(
contractURI_
)
)
));
}发布于 2022-07-15 09:07:30
为了让Opensea读取我的合同元数据,我挣扎了一段时间,Maibe --这可以帮助我:
https://ethereum.stackexchange.com/a/131807/99976
编辑。增加了基本解释:
基本上,我使用一个简单的http服务器提供了一个.json文件。
即。我的元数据保存在metadata.json中
我的contractURI()返回以下内容:
https://www.myCoolDomain.com/metadata.jsonhttps://ethereum.stackexchange.com/questions/110924
复制相似问题