【问题标题】:Erorr after truffle compile in Erc721 openzeppelin contract在 Erc721 openzeppelin 合约中 truffle 编译后出错
【发布时间】:2021-10-08 16:42:03
【问题描述】:

我正在逐步完成这个article,我在truffle compile 部分遇到了问题。 我在cmd中遇到了这个错误:

Error parsing @openzeppelin/contracts/token/ERC721/ERC721.sol: ParsedContract.sol:51:72: ParserError: Expected '{' but got reserved keyword 'override'
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
                                                                   ^------^

我的合同:

pragma solidity ^0.6.0;

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

contract Uniken is ERC721{

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


  constructor() public ERC721("Uniken", "Ukn") {
   }
  
  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(); 
        _mint(recipient, newItemId); 
        _setTokenURI(newItemId, metadata);  
        return newItemId;
  }

}

如果有人告诉我问题出在哪里,我将不胜感激?

【问题讨论】:

    标签: solidity smartcontracts openzeppelin nft


    【解决方案1】:

    似乎没有看到 ERC721 扩展自 ERC165 合同。它卡住的那个函数应该覆盖 ERC165 中的同名函数,但是 truffle 编译器在 ERC721 继承的类中没有看到名为 supportsInterface() 的函数。因此,我会检查以确保在 ERC721 智能合约中导入的所有内容都在您的文件夹结构中的正确位置,并且 ERC721 正确继承了 ERC165。

    【讨论】:

      【解决方案2】:

      经过一番研究,我在 truffle 5.0 版并更新到最新版本的 truffle -> v5.4.6,我现在可以编译了

      【讨论】:

        猜你喜欢
        • 2021-10-06
        • 1970-01-01
        • 2021-11-14
        • 1970-01-01
        • 1970-01-01
        • 2021-07-01
        • 2021-10-06
        • 2022-08-11
        • 2021-01-13
        相关资源
        最近更新 更多