简体   繁体   English

tokenOfOwnerByIndexERC721 时执行恢复错误

[英]Execution reverted error while tokenOfOwnerByIndexERC721

Error while trying to get tokenId by index from Matic Polygon Testnet account尝试通过 Matic Polygon Testnet 帐户的索引获取 tokenId 时出错

"maticProvider": "https://polygon-mumbai.infura.io/v3/<project_id>",
"parentProvider": "https://goerli.infura.io/v3/<project_id>"

Code:代码:

const network = new Network(config.network, config.version);
// TODO do somthing about the unused
const MaticNetwork = network.Matic;
const MainNetwork = network.Main;

const matic = new Matic({
  maticProvider: config.maticProvider,
  parentProvider: config.parentProvider,
  rootChain: MainNetwork.Contracts.RootChain,
  withdrawManager: MainNetwork.Contracts.WithdrawManagerProxy,
  depositManager: MainNetwork.Contracts.DepositManagerProxy,
  registry: MainNetwork.Contracts.Registry
});

matic.tokenOfOwnerByIndexERC721(
    '<accountAddress>',
    '<tokenAddress>',
     0, {
       from: '<accountAddress>',
       gas: 150000
     })
     .then(console.log)

This throws the error这会引发错误

(node:16166) UnhandledPromiseRejectionWarning: Error: Returned error: execution reverted
    at Object.ErrorResponse (/Users/tcadmin/Documents/hub/trove/trove-matic/node_modules/web3-core-helpers/lib/errors.js:28:19)
    at /Users/tcadmin/Documents/hub/trove/trove-matic/node_modules/web3-core-requestmanager/lib/index.js:303:36
    at XMLHttpRequest.request.onreadystatechange (/Users/tcadmin/Documents/hub/trove/trove-matic/node_modules/web3-providers-http/lib/index.js:98:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/tcadmin/Documents/hub/trove/trove-matic/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/Users/tcadmin/Documents/hub/trove/trove-matic/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (/Users/tcadmin/Documents/hub/trove/trove-matic/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (/Users/tcadmin/Documents/hub/trove/trove-matic/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1221:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

Contract:合同:

//Contract based on https://docs.openzeppelin.com/contracts/3.x/erc721
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

// implements the ERC721 standard
import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
// keeps track of the number of tokens issued
import "../node_modules/@openzeppelin/contracts/utils/Counters.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";

    // Accessing the Ownable method ensures that only the creator of the smart contract can interact with it
    contract MyNFT is ERC721, Ownable {
        using Counters for Counters.Counter;
        Counters.Counter private _tokenIds;
        using Strings for uint256;
    
        // the name and symbol for the NFT
        constructor()//(string memory _name, string memory _symbol)
            ERC721("TroveNFT", "TNFT") {}
    
        // Optional mapping for token URIs
        mapping (uint256 => string) private _tokenURIs;
    
        // Base URI
        string private _baseURIextended;
        string private _creatorSign;
    
        function _setCreatorSignature(string memory signature_) internal virtual {
            _creatorSign = signature_;
        }
    
        function _creatorSignature() public view returns (string memory) {
            return _creatorSign;
        }
    
        function setBaseURI(string memory baseURI_) external onlyOwner() {
            _baseURIextended = baseURI_;
        }
    
        function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
            require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
            _tokenURIs[tokenId] = _tokenURI;
        }
    
        function _baseURI() internal view virtual override returns (string memory) {
            return _baseURIextended;
        }
        
        function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
            require(_exists(tokenId), "ERC721Metadata: 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));
            }
            // If there is a baseURI but no tokenURI concatenate the tokenID to the baseURI.
            return string(abi.encodePacked(base, tokenId.toString()));
        }
    
        // Create a function to mint/create the NFT
        // receiver takes a type of address. This is the wallet address of the user that should receive the NFT minted using the smart contract
        // tokenURI takes a string that contains metadata about the NFT
        function mintNFT(address receiver,
                         string memory creator,
                         string memory tokenURI_) public onlyOwner returns (uint256) {
            _tokenIds.increment();
    
            uint256 newItemId = _tokenIds.current();
            _mint(receiver, newItemId);
            _setTokenURI(newItemId, tokenURI_);
            _setCreatorSignature(creator);
    
            // returns the id for the newly created token
            return newItemId;
        }
    }

Please help !请帮忙 !

Found the issue.发现问题。

The contract needs to extend ERC721Enumerable to have tokenOfOwnerByIndex implemented in it.合约需要扩展ERC721Enumerable以在tokenOfOwnerByIndex实现tokenOfOwnerByIndex

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MetaMask - RPC 错误:执行恢复 {code: -32000, message: 'execution reverted'} 在尝试连接到智能合约时 - MetaMask - RPC Error: execution reverted {code: -32000, message: 'execution reverted'} while trying to connect to smart contract MetaMask - RPC 错误:执行恢复{代码:-32000,消息:&#39;执行恢复&#39;} - MetaMask - RPC Error: execution reverted {code: -32000, message: 'execution reverted'} 警告! 合约执行期间遇到的错误 [已恢复] - Warning! Error encountered during contract execution [Reverted] Web3.js 返回错误:执行已恢复 - Web3.js returned error: execution reverted 当我在 goerli tes.net 上调用 createCollectible function 时出现“执行恢复”错误 - "Execution reverted" error when I call createCollectible function on goerli testnet brownie:ValueError: execution reverted: VM Exception while processing transaction: revert - brownie:ValueError: execution reverted: VM Exception while processing transaction: revert 执行恢复{“originalError”:{“代码”:3,“数据”:,“消息”:“执行恢复”}} - execution reverted { "originalError": { "code": 3, "data": , "message": "execution reverted" } } 什么是错误错误:返回错误:调用区块链数据时恢复执行以及如何修复? - What is error Error: Returned error: execution reverted when calling blockchain data and how to fix it? 在智能合约 Fundme 中出现错误,错误是“VM 执行错误。恢复为 0x” - Getting an error in smart contract Fundme, The error is "VM execution error. Reverted to 0x" 如何在本地测试网上诊断 ERC20 错误“错误:执行已恢复”? - How to diagnose an ERC20 error "Error: execution reverted" on a local testnet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM