Facing an error that caller is not approved

Hey everyone, I am facing an error called:

 transact to LotteryEscrowParent.callPurchaseItem pending ... 
transact to LotteryEscrowParent.callPurchaseItem errored: Error occured: revert.

revert
	The transaction has been reverted to the initial state.
Reason provided by the contract: "Caller does not have approval".
Debug the transaction to get more information.

however, I have already provided the code for approval. Here's the code:

 function purchaseItem(uint256 tokenId, address collectionContract) external payable {
        //uint256 _totalPrice = getTotalPrice(tokenId);
        MarketItem memory item = marketItems[tokenId];
require(IERC721(item.nftContract).getApproved(tokenId) == address(this), "Caller does not have approval");
        require(!item.sold, "item already sold");
        payable(item.seller).transfer(msg.value);
        item.sold = true; 
        IERC721(item.nftContract).transferFrom(item.seller, msg.sender, tokenId);
        marketItems[tokenId].owner = payable(msg.sender);
        soldItems[collectionContract].push(tokenId);
        emit Bought(address(this), item.tokenId, msg.value, item.seller, msg.sender);
    }
  function callPurchaseItem(
         uint256 tokenId,
         address tokenAddress,
         address collectionContract
      )public payable{
require(IERC721(tokenAddress).getApproved(tokenId) == address(this), "Caller does not have approval");
    LotteryEscrow(tokenAddress).purchaseItem{value: msg.value}(tokenId, collectionContract);
        // require(msg.sender == IERC721(tokenAddress).ownerOf(tokenId), "caller is not token owner");
      }

Can anyone help me with this?
Thank you:)

What does that even mean? Provided to who? And why would that solve any problem whatsoever?

Please provide the details of the reverting transaction:

  • Which function you are trying to execute
  • What input values you are passing to it

I am trying to execute callPurchaseItem function and passing tokenId, tokenAddress and collectionContract address

This is definitelly the line that fails.

Not that the message of the error does not match the actual check. The check verifies that contract is authorized to operate on the token. It does NOT check that the caller of the transaction (msg.sender) has a approval.

You say you provided tha approval. How did you perform that operation. Keep in mind that you check the tokenId approval, so enabling an operator is not working here. Also, keep in mind that transfering the token does reset this approval.

1 Like

Okay, then how do I solve this one?