6

Is there any way in the Web3 Javascript API to retrieve the latest, let's say five, transactions that were done on the blockchain?

The only option I can think of, is by using web3.eth.getBlock(web3.eth.blockNumber, true) in a for loop and subtracting the blockNumber till you find an object in the transactionsproperty.

However, this can take a very long time, because in our case, we have our blockchain on an Azure server and a lot of empty blocks are created by nodes.

EDIT: Not a duplicate of this. I want to know how to find the latest transactions in an efficient way, without using a for loop that takes ages to complete.

2
  • 1
    I want to know how to find the latest transactions in an efficient way, without using a for loop that takes ages to complete.
    – Nickkerd
    Commented Mar 15, 2017 at 13:27
  • I posted an answer that shows how to use BatchRequest to reduce the amount of network requests
    – vilsbole
    Commented Dec 6, 2018 at 14:07

1 Answer 1

2

UPDATE:

I found this example on Github, someone found a way to scan blocks for transactions asynchronously! If you have a decent CPU, you can hit 300 blocks/second. It is very well documented as well.

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