0

I know the reasons for using transfer vs transferFrom but made the mistake of using the second one whilst doing some testing and I got the error "ERC20: transfer amount exceeds allowance". The sender was the same address as the signing wallet so to me this would feel the same as using the transfer method as the signing wallet at that point is basically trying to send its own tokens.

Is there are particular reason this design decision was chosen?

Obviously I can call approve on my own wallet for my own tokens and then use the transferFrom function, but this feels slightly counter intuitive. If the transferFrom function had a check ie

if(msg.sender != sender)

In this case it could then check the approved amount. If this was the case then potentially the two could be used interchangeably. Although I do recognize that having then two functions that perform the same operation would also be counter intuitive.

This is more a point of curiosity and I can't find any info that explains this.

1 Answer 1

0

transferFrom () gives you option of allowing another address to take specified amount of tokens from your address (That is basic use case for that function).

Making sure you are "allowed" to take tokens from your own address and send them back to yourself is not a realistic use case.

Ofcourse, you can do it for fun, but no one would waste gas/eth to do it.

I think that makes sense if you look at it form that angle.

2
  • The revert happens with transferFrom(me, you, amount) Commented Apr 28, 2022 at 19:37
  • To use transferFrom () you first need to call approve () function. (It sets the amount you are willing to allow another address to take from you)
    – Sky
    Commented Apr 28, 2022 at 19:47

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.