I've been learning about the ERC20 standard and I've seen in several places statements like
If a smart contract want to detect when it receives a transfer of ERC20 tokens the standard approach is for the user to approve the transfer and for the smart contract to complete it doing a transferFrom from the user.
It is said that this pattern is particularly useful for exchanges that receive and manage multiple ERC20 tokens for their users. But can't the same thing be accomplished by listening to the contracts' Transfer events?
For example, if Uniswap wants to detect when a user sends them DAI. They can do 1 of the 2 things:
- The approve/transferFrom pattern where the user approves their contract address for the x DAI and then the Uniswap contract transfers the funds from the user's balance to their balance
- Setup an event listener on the DAI contract's Transfer event and acknowledge all the events with their address in the "to" field
Maybe there are other consideration I'm neglecting but doesn't the second approach accomplish the same effect in less transactions?