I have a scenario where a user approves an allowance of a standard erc20
token to a contract address using the approve
function as follows using the truffle console.
TOKEN.approve("contractAddress", 10000000)
It generates a tx
and when I check the allowance using the allowance
function, I can see the approved allowance as
TOKEN.allowance(account[0], "contractAddress")
It gives me the correct amount and I can also see the correct tx and data in the transaction.
The issue is when I call the same allowance
function from inside a contract (where the tokens were sent to), I never get the amount.
The following function in my Contract.
function checkUserAllowance() public virtual returns (bool) {
// load contract interface
IERC20 TOKEN = IERC20("contractAddress"); // I can verify it is the correct address
// check the approved allowance
uint256 allowance = TOKEN.allowance(msg.sender, address(this));
require(allowance > 0, "No approved allowance");
return true;
}
When calling checkUserAllowance
I always get the "No approved allowance" message and it never goes through. I can confirm that I am sending requests from the correct user.
Any idea what am I doing wrong?