0

I am using the IERC721.transferFrom() openZeppelin interface. When I try to transfer the NFT from msg.sender(me) to the contract (address.(this)) I get a Fail with error 'ERC721: transfer caller is not owner nor approved' error. I am trying to list an NFT to my marketplace without having to do multiple transactions. What am I missing?

contract Market is OwnableUpgradeable, ReentrancyGuardUpgradeable {
 function _createListing(
    address nftAddress,
    uint256 tokenId,
    address _listingTokenAddress,
    string calldata _listingTokenName,
    string calldata _listingTokenSymbol,
    uint256 price,
    uint256 expiration
) internal {
    require(nftAddress != address(0), "zero address");
    require(price > 0, "zero amount");
    IERC721Upgradeable(nftAddress).transferFrom( //<-- Issue line
        msg.sender,
        address(this),
        tokenId
    );
    PropertyListing memory _propertyListing = PropertyListing(
        nftAddress,
        tokenId,
        price,
        _listingTokenAddress,
        _listingTokenName,
        _listingTokenSymbol,
        msg.sender,
        expiration,
        true,
        false
    );
    listings.push(_propertyListing);
    uint256 _id = listings.length - 1;
    emit NewPropertyListing(
        _id,
        nftAddress,
        tokenId,
        price,
        _listingTokenAddress,
        _listingTokenName,
        _listingTokenSymbol,
        msg.sender,
        expiration,
        true,
        false
    );
}
}

1 Answer 1

0

If you use transferFrom() function, a user must to approve your smart contract to move his token. And only if user has approved this operation you can called _createListing() from your smart contract. In your case, a user must to call approve() function from nft smart contract address with this parameters:

  • to: your smart contract address;
  • tokenId: token that must to move into your smart contract.

After this operation, you can call _createListing() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.