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:)