TransWikia.com

How to query incoming transactions to an ethereum address via web3j?

Ethereum Asked by Arvind on November 20, 2021

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!!

One Answer

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.

Answered by sp4c3 on November 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP