6

I am trying to build a dapp which will monitor a particular address balance, and update in case someone send fund (ether) to it.

Instead of polling using call getBalance, I want to take advantage of the relatively new subscription API through WebSocket (https://github.com/ethereum/go-ethereum/wiki/RPC-PUB-SUB). While I can successfully connect geth using WebSocket, I am struggling to apply the correct filter to the subscription.

Which subscription type should I use? If I use newHeads or newPendingTransactions, what is the correct filter for this kind of case? BTW, I try "logs" before, it seems that the address parameter is only for contract address but not "regular" address (if you understand what I mean).

Thank you.

1 Answer 1

2

Eventually, I developed a proof-of-concept. I posted the source in GitHub at https://github.com/AlanL1/Ethereum-FrontEnd

The code that might be useful to you is in transaction.html. I use subscription type newHeads, and scan through all the new blocks using getTransactionFromBlock. The performance is okay since I am not polling and only react if a new block arrives. Still, if anyone come up with a better solution please share with us.

1
  • I'm trying to run source code, but it gives me an error Unable to connect to geth how to connect geth?
    – Div
    May 12, 2018 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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