1

Fallback functions only work when a contract receives ether. Is there a way to write a fallback-style function that is automatically called when a contract receives an ERC20 token?

1 Answer 1

2

There is a reference implementation in EIP 677 and also in ERC223

This function must transfer tokens and invoke the function tokenFallback (address, uint256, bytes) in _to, if _to is a contract.

The token fallback function, which will be called at the receiver contract, must be named tokenFallback and take the parameters:(address, uint256, bytes). It’s an analogue of the fallback function for ETH transactions and should be used to handle incoming transactions.

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.