0

I want to be be able to programmatically detect an ETH deposit in order to process it as a payment in my app.

I have been looking into an etherscan.io API and the only way i found to detect incoming transactions was by doing a cron job and constantly monitoring the list of transactions.

Is there a better way?

3
  • please describe your use case in more detail. what do you want to do then? If you, e.g. want to trigger a smart contract then you could pay into a smart contract right away. If you want to trigger a backend process then you might want to work with web3.js.
    – SCBuergel
    Feb 11, 2018 at 15:41
  • I want to be able to detect ether desposits in a certain address in order to process payments in my app. Feb 11, 2018 at 18:33
  • Please don't flag it. That question you quoted does not answer my question specifically. Feb 12, 2018 at 9:24

1 Answer 1

2

It doesn't sound like you're approaching this from the best angle. Etherscan is just a web service that monitors the entire network -- relying on it for something like transaction processing is far from the most ideal way to interact with the blockchain.

Ethereum is a distributed network, which means that anyone can run a node that sees the data that Etherscan gets. In practice, this means that you need to run either Geth or Parity (or some other node) to see the entire chain. What do you get from either geth or parity? The JSON-RPC API.

Most of the time, when people implement payment systems using a blockchain, they generate a unique address and private key for each customer transaction. This gives you an assurance that one customer is paying for only one customer's account, and makes your life a lot simpler. The eth_getbalance JSON-RPC endpoint can tell you that an address has a balance. If you've generated a unique address for each customer, you can just query your local JSON-RPC API repeatedly for the balance of the address you issued them. When the balance at that address matches your set price, you know the transaction has been completed. Most companies wait for a given number of "confirmations," aka, new blocks on the network after the transaction containing yours is there. This ensures that no replay attack has been done against you.

This is the most naive approach, but it shows you the technology you need to move forward. In short:

  1. Run your own node.
  2. Query your own node for the transaction against a unique address for a customer, using the JSON-RPC API.
  3. Verify that the address has the amount you expect it to (your transaction has been completed at this point) after a given number of new blocks.

You can improve this by listening for new blocks, watching other events, etc. The JSON-RPC interface is also crude, but some APIs exist on top of it that let you query it easier. For example, check out web3.js.

3
  • Isn't it much work to continously manage many wallets? How do i withdraw all the funds to a single wallet? Its going to have costs. Mar 14, 2018 at 22:20
  • can I query transactions directly instead of balances ? Dec 10, 2018 at 18:00
  • @PavelNiedoba you would be better off asking any further questions in a new question.
    – hakusaro
    Dec 10, 2018 at 19:33

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