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.
Best Answer
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 usinggetTransactionFromBlock
. 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.