2

I want to show a button with 2 states (APRROVE USDC) and (CONFIRM SWAP). But, I do not how to get from the ERC20.sol contract a variable o methods that returns if the token was already approved or not.

1 Answer 1

3

You can use the allowance method to check if the spender is approved to transfer tokens on behalf of the owner. the method will return you the approved amount to spend

https://docs.openzeppelin.com/contracts/2.x/api/token/erc20#IERC20-allowance-address-address-

allowance(address owner, address spender) → uint256 external Returns the remaining number of tokens that spender will be allowed to spend on behalf of owner through transferFrom. This is zero by default.

This value changes when approve or transferFrom are called.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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