Reputation: 31
I'm getting ERC721 transfer of token that is not own. any help, please?
Unhandled Rejection (Error): cannot estimate gas; transaction may fail or may require manual gas limit (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":
Creat ERC721 Token:
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;}
Put on Sale and transfer:
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); }
Upvotes: 3
Views: 5152
Reputation: 49
I was having same error and I came up with 2 solutions:
In your hardhat.config.js
, add manual gas limit in networks:
your network: {
url: `https://rinkeby.infura.io/v3/${process.env.PROJECT_ID}`,
accounts: [privateKey],
gas: 2100000,
gasPrice: 8000000000,
}
In your index.js
file, instead of mainnet in Web3Modal
, use your network:
const web3Modal = new Web3Modal({
network: "your network name",
cacheProvider: true,
})
Upvotes: 5