I'm looking to integrate ERC-20 Token into my shop. Now I have a lot of products so I need automated system to keep track of payments. I did some reading and it looks like if I write smart contract to handle this I would need to prompt user two times (one for allowance and one for transfer) which is not great. I wonder what is the common practice of handling this issue ? I know that ERC-223 solves that problem but unfortunately most tokens are ERC-20.

Another solution is maybe to generate new address for each purchase, but then I would need to transfer ETH to each address in order to move tokens which could get very expensive.

1 Answer 1


You can use events which are a part of the ERC20 definition to keep track of payments. The Transfer event is triggered when someone makes a payment. So you need to listen for Transfer events where the _to parameter matches your recipient address.

Transfer(address indexed _from, address indexed _to, uint256 _value)

You may still have the problem of two customers buying the same product at the same time which would make it impossible to differentiate who has paid and who has not paid. If you do not want to use separate receiving accounts for each payment, you can use separate amounts for each payment: You could cycle through different values at the least significant digits (1-3 digits) of the amount (the smallest possible values usually are not worth anything). You could also cycle through various payment addresses, thus having only ten or one hundred payment addresses that you receive on, making sure that only one is in use at a time.

You could even use a combination of these two strategies to all but eliminate the risk of a "payment collision" where you are unable to differentiate between two payment requests.

  • I did think of that. But what if for example 2 transactions of same product (same value) are happening at the same time ? I have no control over what someone buys and at what time. Then I would need to listen to two events on the same _to address and same _value. How should I differentiate them ? Apr 28, 2018 at 12:42
  • You are right. Exchanges solve this problem by giving each customer their own deposit address. A more hacky solution would be to make the amount of each transaction unique by cycling through specific values on its least significant digits. Does that make sense? Apr 28, 2018 at 12:59
  • It kinda does.... Its not a bad solution. Thanks ! Apr 28, 2018 at 13:09
  • I updated the answer which now contains one more possible solution. Apr 28, 2018 at 13:15
  • 1
    Thanks for your time, really great answer if someone is having same problem as me Apr 28, 2018 at 13:42

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.