0

This question already has an answer here:

Differently from receiving ethers which goes through a payable code block, receiving tokens is not managed by the recipient but by the token contract code. Hence, in case you want your contract to perform some action when he receives tokens, which practice is best to use?

EDIT: I'm aware of EIPs to enhance token interface to manage this, however my question is how to work this around for ERC20 tokens.

marked as duplicate by Mikko Ohtamaa, Achala Dissanayake, Richard Horrocks, eth Apr 7 '18 at 22:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Your contract won't be aware of any tokens sent to it. Instead of asking people to sent tokens to your contract you can ask them to do approveAndCall(address spender, uint tokens, bytes data) which is part of the standard ERC20.

You will need to implement in your contract the ApproveAndCallFallBack function.

In this way, you will be aware of tokens being sent to your contract. Other ERC standards will allow what you are looking for directly, but what is described above is what is available for ERC20.

  • I'm afraid this simply doesn't work if tokens are sent with a wallet like Metamask or MEW, does it? – Davide C Apr 7 '18 at 14:01
  • You are right, it won't. I assume that your contract offers some kind of service. you can have a website connected to metamask where they can pay or send and when they do they will be executing approveAndCall rather than transfer. You should be clear with the users though. – Jaime Apr 7 '18 at 15:03

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