When trying to get events from a smart contract from block 18412471 to LATEST, I immediately get a timeout error. If I do the same but from block 18412471 to, for example, block 18412585, the program runs with no error.
Hi,
Can you also share a minimal code of how you are getting those events?
Hi, sure.
hub.contractsChangedEventFlowable(start, end).subscribe(
response -> { //dosomething }, Throwable::printStackTrace);
this is the contractsChangedEventFlowable method definition :
public Flowable<ContractsChangedEventResponse> contractsChangedEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(CONTRACTSCHANGED_EVENT));
return contractsChangedEventFlowable(filter);
}
and this is the the other definition :
public Flowable<ContractsChangedEventResponse> contractsChangedEventFlowable(EthFilter filter) {
return web3j.ethLogFlowable(filter).map(log -> {
EventValuesWithLog eventValues = extractEventParametersWithLog(CONTRACTSCHANGED_EVENT, log);
ContractsChangedEventResponse typedResponse = new ContractsChangedEventResponse();
typedResponse.log = log;
return typedResponse;
});
}
What happens if you skip to block, as in you don’t put LATEST and you don’t even set that parameter for to block?
What do you mean ? The “to block” parameter is needed to create the filter :
https://docs.web3j.io/4.8.7/javadoc-api/org/web3j/protocol/core/methods/request/EthFilter.html
I assumed that it will use a default value if you don’t specify it.
Here I don’t see a to block
parameter (if this is the equivalent in javascript of what you are doing):
https://web3js.readthedocs.io/en/v1.5.2/web3-eth-subscribe.html#subscribe-logs
Web3j and Web3js are different libraries and have different methods.
The toBlock
parameter of the method in Web3js is optional and defaults to latest
if not specified.
In Web3j you must specify that parameter. Anyway there should be no difference when specifying LATEST
.