1

i know this question has been asked many times in this forum, but none of them give clear cut answer to the questions. I tried the snippet mentioned in this answer: Common useful JavaScript snippets for geth ; But, it gives me the reply as "undefined" when run in the node.

Can someone please guide me on how i can query the blockchain to get incoming transactions to an address?

Thanks!!

Arvind
  • 75
  • 7
  • There is no such functionality in Web3 API, and in general there is no effective way to implement it, because nodes do not index incoming transactions. Though, this may help in some cases: https://github.com/ethereum/go-ethereum/pull/15512 – Mikhail Vladimirov Mar 18 '19 at 14:16

1 Answers1

0

You can try this for upcoming transaction in latest blocks, even though I feel that the frequency of watch here is a bit high to use it in any application.


var address = web3.eth.accounts[0];     
var filter = web3.eth.filter('latest');

filter.watch(function(error, result){
    var block = web3.eth.getBlock(result, true);
    console.log('current block #' + block.number);

    if(block.transactions.length)
        for(var index in block.transactions)
            if(block.transactions[index].to == address)
                console.log(block.transactions[index]);
});

Hope this helps.

sp4c3
  • 440
  • 2
  • 12