I want to retrieve the transaction history between 2 blocks and I came upon this replay filter To replay the individual transactions contained within a range of blocks:
Subscription subscription = web3j.replayTransactionsObservable( <startBlockNumber>, <endBlockNumber>) .subscribe(tx -> { ... });
However, I am unable to find any working example related of this filter. Can anyone just help in providing a working example?
Simply getting access to the transaction objects is pretty straightforward:
will print out all of the transactions that have occurred on the peer node running on your localhost. Just change
System.out::println
totx -> //do something with tx
(tx
is aorg.web3j.protocol.core.methods.response.EthBlock$TransactionObject
).Note that this will only replay the history. You won't see any new transaction objects as blocks are added to the chain.
A more complicated example of using subscriptions comes if you want to do something like listen for specific events emitted. I've included an example of that below in case it helps. If you need help with a specific problem, please post questions with more details and sample code.