gpt4 book ai didi

solidity - 错误 : cannot estimate gas; transaction may fail or may require manual gas limit ERC721: transfer of token that is not own"

转载 作者:行者123 更新时间:2023-12-05 01:57:41 56 4
gpt4 key购买 nike

我正在获取不属于自己的代币的 ERC721 转移。有什么帮助吗?

未处理的拒绝(错误):无法估计气体;交易可能会失败或可能需要手动 gas 限制(error={"code":-32603,"message":"execution reverted: ERC721: transfer of token that is not own","data":{"originalError":{"code":3,"data":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a207472616e73666572206f6620746f6b656e2074686174206973206e6f74206f776e0000000000000000000000000000000000000000000000","message":"execution reverted: ERC721: transfer of token that is not own"}}}, method="estimateGas", transaction={"from":"0xFeB43BA464258c453D7aA678210fD49zxnFRgfBN ","to":"0x81b6BfD84f5FBa7c737382Bd535875DDF4bFD443","value":

创建 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;}

发售和转让:

 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); }

最佳答案

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

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

    your network: {
    url: `https://rinkeby.infura.io/v3/${process.env.PROJECT_ID}`,
    accounts: [privateKey],
    gas: 2100000,
    gasPrice: 8000000000,
    }
  2. 在您的 index.js 文件中,使用您的网络代替 Web3Modal 中的主网:

    const web3Modal = new Web3Modal({
    network: "your network name",
    cacheProvider: true,
    })

关于solidity - 错误 : cannot estimate gas; transaction may fail or may require manual gas limit ERC721: transfer of token that is not own",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68909451/

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