我想做个小型NFT。在部署智能契约之后可以添加NFT。当我使用URI存储时,是否需要提供基本URI。我正在使用openzeppelin向导来制定智能契约(https://docs.openzeppelin.com/contracts/4.x/wizard)

发布于 2022-05-04 06:02:48
你不需要这么做。您可以查看下面ERC721URIStorage的逻辑,它说,默认情况下,如果没有定义base_uri,它将使用您定义的uri,否则它将使用 + 。或者您可以重写tokenURI函数并实现自己的逻辑。
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token");
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
return super.tokenURI(tokenId);
}https://ethereum.stackexchange.com/questions/127495
复制相似问题