如何将我的IPFS内容链接到ERC721合同?
我正在尝试签订简单的ERC721 NFT铸造合同。我创建了一个图像及其相应的元数据,并将它们上传到IPF。该图像和元数据何时与智能合约中创建的令牌链接?我试图使用与OpenZeppelin合同向导生成的此代码:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract MyToken is ERC721, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("MyToken", "MTK") {}
function safeMint(address to) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}
}
但是我看不到可以将NFT图像和元数据链接到合同的位置。我已经看到,在OpenZeppelin的ERC721 Standart中,您可以使用功能Tokenuri
和_Baseuri
设置基本URI和Tokenuri,但我不知道如何使用它们。我打算创建一个多项目集合(在IPF中),因此我不知道在我的情况下使用什么。
I´m trying to make a simple ERC721 NFT minting contract. I created an image and its corresponding metadata and I´ve uploaded them to the ipfs. When does this image and metadata link with the token created in the smart contract?. I was trying to use this code generated with the Openzeppelin contract wizard:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract MyToken is ERC721, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("MyToken", "MTK") {}
function safeMint(address to) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}
}
But I don't see where I can link my nft image and metadata to the contract. I´ve seen that in ERC721 standart by openzeppelin you can set the base URI and tokenURI with the functions tokenURI
and _baseURI
, but I don't know exactly how to use them. I was planning to create a multiple-item collection (in the ipfs) so I don't know what to use in my case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用ERC721URISTORAGE替换ERC721
Replace ERC721 with ERC721URIStorage