Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (12.7k points)

I have a private chain now and I want to query the transaction histories.I know that web3 has provide those methods web3.eth.blockNumber/web3.eth.getBlockTransactionCount/web3.eth.getTransactionFromBlock. So I can get the transaction history by getting latest blocknumber(suppose it's n). Range from n to 0 to call web3.eth.getBlockTransactionCount(i), then get transactions by web3.eth.getTransactionFromBlock. but it's just time-wasting and inefficient. so I'm wondering how can I get transaction histories from blocks efficient via web3 or RPC or any way?

1 Answer

0 votes
by (29.5k points)

HI, i can think of a way to get your job done but this might not be the most efficient way that you are looking for still, what you can do is  For each block you can pass true as the second parameter to getBlock:

web3.eth.getBlock(blockHashOrBlockNumber [, returnTransactionObjects] [, callback])

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...