错误:无法估计gas;交易可能会失败或可能需要手动gas limit ERC721:转移不属于自己的代币”

use*_*934 3 solidity

我收到不属于我自己的代币的 ERC721 转移。有什么帮助吗?

未处理的拒绝(错误):无法估计gas;交易可能会失败或可能需要手动气体限制(错误= {“代码”:-32603,“消息”:“执行已恢复:ERC721:转移不属于自己的代币”,“数据”:{“原始错误”:{“代码":3,"数据":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000 0000000000000000000000294552433732313a207472616e73666572206f6620746f6b656e2074686174206973206e6f74206f776e000000000000000000 000000000000000000000000000","message":"执行已恢复: ERC721: 转移不属于自己的代币"}}}, method="estimateGas", transaction={"from":"0xFeB43BA464258c453D7aA678210fD49zxnFRgfBN “,”到“:”0x81b6BfD84f5FBa7c737382Bd535875DDF4bFD443“,”值“:

创建ERC721代币:

function createToken(string memory _tokenURI) public returns (uint) {
    _tokenIds.increment();
    uint256 newItemId = _tokenIds.current();

    _mint(msg.sender, newItemId);
    _setTokenURI(newItemId, _tokenURI);
    setApprovalForAll(contractAddress, true);
    return newItemId;}
Run Code Online (Sandbox Code Playgroud)

出售及转让:

 function createSale( address nftContract,
uint256 itemId
) public payable nonReentrant {
uint price = idToMarketItem[itemId].price;
uint tokenId = idToMarketItem[itemId].tokenId;
require(msg.value == price, "Please submit the asking price in order to complete the purchase");
idToMarketItem[itemId].seller.transfer(msg.value);
IERC721(nftContract).transferFrom(owner, msg.sender, tokenId);
idToMarketItem[itemId].owner = payable(msg.sender);
idToMarketItem[itemId].sold = true;
_itemsSold.increment();
payable(owner).transfer(listingPrice); }
Run Code Online (Sandbox Code Playgroud)

小智 5

我遇到了同样的错误,我想出了两个解决方案:

  1. 在您的hardhat.config.js网络中添加手动气体限制:

    your network: {
        url: `https://rinkeby.infura.io/v3/${process.env.PROJECT_ID}`,
        accounts: [privateKey],
        gas: 2100000,
        gasPrice: 8000000000,
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在您的文件中,使用您的网络index.js而不是 中的 mainnet :Web3Modal

    const web3Modal = new Web3Modal({
        network: "your network name",
        cacheProvider: true,
    })
    
    Run Code Online (Sandbox Code Playgroud)