设置令牌 URI 函数
我了解到 setTokenURI 函数不再使用。如何更改我想要创建的 NFT 代币的代币 URI? 现在我的智能合约中的 createCollectible 函数如下所示:
function createCollectible(string memory tokenURI)
public
returns (uint256)
{
uint256 newItemId = tokenId;
_safeMint(msg.sender, newItemId);
_setTokenURI(newItemId, tokenURI);
tokenId = tokenId + 1;
return newItemId;
}
I understood that setTokenURI function isn't in use anymore. How can I change the token URI of the NFT token I want to create?
for now my function createCollectible inside the smart contract looks like this:
function createCollectible(string memory tokenURI)
public
returns (uint256)
{
uint256 newItemId = tokenId;
_safeMint(msg.sender, newItemId);
_setTokenURI(newItemId, tokenURI);
tokenId = tokenId + 1;
return newItemId;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
_setTokenURI
仍然使用,但已移至ERC721URIStorage
。这是 openzeppelin 链接当你创建你的合约时,你应该继承:
由于调用它是一个昂贵的操作,团队希望你在中使用
tokenUri
函数ERC721
:这是从
ERC721
继承的_baseUri()
。它是虚拟的,因此您可以在 ERC721URIStorage 内覆盖它并将其从“”更改为您想要的任何内容。这次你需要继承
ERC721
它们都有不同的用例:在此讨论
_setTokenURI
is still used but it is moved to theERC721URIStorage
. Here is the openzeppelin linkWhen you create your contract, you should inherit:
Since calling it an expensive operation, team wants you to use
tokenUri
function inERC721
:this is
_baseUri()
which is inherited fromERC721
. It isvirtual
so that you canoverride
it insideERC721URIStorage
and change it from "" to anything you want.this time you need to inherit from
ERC721
They both have different use cases: Discussed Here