#javascript #solidity
Вопрос:
Я получаю передачу токена ERC721, который мне не принадлежит. какая-нибудь помощь, пожалуйста?
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":
Создать токен 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);
}