3


Question regarding Web3j library. How can I replay all the logs from the blockchain using web3j ? I know there is a method to replay all the logs from a particular contract:

EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST,
        DefaultBlockParameterName.LATEST, "0xafc785653c...")

web3j.ethLogObservable(filter).subscribe(
    event => {
      println(event.toString)
    }
  )

And it works fine, however when filter is created without parameters -new EthFilter(), it doesn't capture any logs at all.
What if I have 1000 contracts to listen to events from ? What is the best way to go about this ?

Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48
RB_
  • 1,195
  • 15
  • 35

1 Answers1

1
public EthFilter(DefaultBlockParameter fromBlock, DefaultBlockParameter toBlock,
                 List<String> address) {
    super();
    this.fromBlock = fromBlock;
    this.toBlock = toBlock;
    this.address = address;
}

As of Web3J version 3.6.0, you can pass a list of contract addresses to hear events from.

Although creating a list of 1000 contracts addresses manually is troublesome, you can maintain a file or db table from which you can fetch the contract addresses. I hope this answer helps.

Sangat Das
  • 106
  • 2
  • 3