gpt4 book ai didi

ethereum - 声明错误 : Undeclared identifier - although it's present in ERC721. sol

转载 作者:行者123 更新时间:2023-12-04 00:50:43 24 4
gpt4 key购买 nike

我正在写一份关于 Solidity 0.8.3 的契约(Contract),我收到了 _setTokenURI() 这个奇怪的错误虽然方法是defined in OpenZeppelin 4.X .

pragma solidity ^0.8.3;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract NFTB is ERC721 {

using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
mapping(string => uint8) hashes;

constructor() public ERC721("NFTB", "NFTB") {}

function awardItem(address recipient, string memory hash, string memory metadata) public returns (uint256) {
require(hashes[hash] != 1);
hashes[hash] = 1;
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_setTokenURI(newItemId, metadata);
_mint(recipient, newItemId);
return newItemId;
} }
enter image description here

最佳答案

功能 _setTokenURI()@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol 中定义( source on GitHub ),但此合约不是由您的代码导入的(包括嵌套导入)。这就是未声明函数的原因。
ERC721URIStorage扩展 ERC721 ,您可以扩展您的 NFTB直接来自 ERC721URIStorage .

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; // changed import
import "@openzeppelin/contracts/utils/Counters.sol";

contract NFTB is ERC721URIStorage { // changed parent

关于ethereum - 声明错误 : Undeclared identifier - although it's present in ERC721. sol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66789290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com