0
[Sender] -> [My Contract] -> [ERC20 Contract]

The sender invokes my Contract, and my contract in turns will invoke ERC20 contract to Transfer token on behalf of the senders (using his msg.sender).

However, the ERC20 contracts Transfer() function msg.sender will become the My Contract's address instead of the Sender's address.

May I know what is the correct way for My Contract to Transfer a Token on behalf the Sender?

1

You cannot do this using the ERC20 transfer(..) function.

You will need to call the transferFrom(..) function on the ERC20 contract.

To be able to use transferFrom(..), your [Sender] will first have to call approve(..) on the ERC20 contract to allow your contract to use transferFrom(..).

  • My contact cannot call approve on behalf of the sender. If the sender can call approve himself, why not he just send the token directly to the other contract? This method is a bit redundant and gas wasting – s k Jul 13 '18 at 8:20
  • @sk You wanted your contract to transfer on behalf of the sender. If the sender did not need to give permission, any contract could steal anyone's tokens. That's why an approval is necessary. – Jesse Busman Jul 14 '18 at 11:26
  • @Jessee, I was hoping someone come out with ERC677 or even a better idea. IMHO the transfer / approve mechanism in ERC20 is flaw, it waste gas, and creates a race condition (non thread safe) – s k Jul 15 '18 at 0:09
  • @sk I agree. ERC223 or ERC677 would be better suited to this purpose, but your question was about an ERC20 contract :) – Jesse Busman Jul 15 '18 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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