1

Could you please enlighten me on how approve and allowance functions work using a usecase? I dont understand the underlying operations of these functions. Especially, when a token owner delegates the right to spend his token by other user: how the ownership sign-off works, is this be done automatically?

1

1 Answer 1

3

The original use case from back 2016 is that back in a day, smart contracts had no way to interact to incoming token transfer. (This has been now fixed with ERC-777 token standard and send()).

For you to interact with a smart contract with an ERC-20 token

  1. You need to approve() amount of tokens on a smart contract address

  2. You call a smart function that then in a turn calls token.transferFrom() function to take over the tokens from you and do something with them

allowance() is simply a function to check what's the current approve() limit.

2
  • Thanks Mikko! This means, the contract that I approve would use my address to sign-off tokens which require signing-off using my private key right? Does the signing-off happen seamlessly?
    – Muni V K
    Commented May 20, 2020 at 17:27
  • After the approve() has been done the smart contract is free to use the tokens and one can consider "the posession of" tokens to be on the smart contract. approve() is the only transaction that depends on your private key. Smart contract can control the tokens until you cancel to approve() by setting it to zero. Commented May 21, 2020 at 10:53

Your Answer

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

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