Yes still not connecting Here’s my code which is working fine on the Rinkeby version BTW: I’ve even whitelisted my contract
address:
/////////////////////////////////// Connection code: ///////////////////////////////////
Web3j web3j = connect(“wss://mainnet.infura.io/ws/v3/2a9a4f645bf64a378b5352497557e0db”);
…
private Web3j connect(String url) throws IOException {
Objects.requireNonNull(url, “ethereum.node.url cannot be null”);
Web3j web3j;
//////// WEBSOCKET ///////////////////////////////////
if (url.startsWith(“ws”)) {
WebSocketService web3jService = new WebSocketService(url, true);
web3jService.connect();
web3j = Web3j.build(web3jService);
//////// HTTP ///////////////////////////////////
} else {
web3j = Web3j.build(new HttpService(url));
}
if (log.isDebugEnabled()) {
String clientVersion = web3j.web3ClientVersion().send().getWeb3ClientVersion();
log.debug(“Connected to Ethereum node {} : {}”, url, clientVersion);
}
return web3j;
}
/////////////////////////////////// Subscription code: ///////////////////////////////////
String contractAddress = “0xContractAddressListedHere”;
EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, contractAddress);
web3j.ethLogFlowable(filter).subscribe(log -> {
System.out.println(log.toString());
System.out.println(log.getTransactionHash());
List<Type> args = FunctionReturnDecoder.decode(log.getData(), MY_EVENT.getParameters());
System.out.println("-----------------------------------------------------------------------------------");
System.out.println(new Date());
System.out.println("TxHash : "+log.getTransactionHash());
System.out.println("Buyer : "+args.get(0).getValue());
System.out.println("Amount : "+Convert.fromWei(""+args.get(1).getValue(), Convert.Unit.ETHER));
System.out.println("-----------------------------------------------------------------------------------");
}, throwable -> {
System.out.println(new Date());
System.out.println(throwable.getMessage());
throwable.printStackTrace();
});
///////////////////////////////////
//================================================
Receives the following error after some pause:
[WebSocketConnectReadThread-13] INFO org.web3j.protocol.websocket.WebSocketClient - Opened WebSocket connection to wss://mainnet.infura.io/ws/v3/2a9a4f645bf64a378b5352497557e0db
Mon Feb 25 18:29:30 EST 2019
Error sending request
org.web3j.protocol.core.filters.FilterException: Error sending request
at org.web3j.protocol.core.filters.Filter.throwException(Filter.java:176)
at org.web3j.protocol.core.filters.Filter.run(Filter.java:92)
at org.web3j.protocol.rx.JsonRpc2_0Rx.run(JsonRpc2_0Rx.java:73)
at org.web3j.protocol.rx.JsonRpc2_0Rx.lambda$ethLogFlowable$15(JsonRpc2_0Rx.java:65)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:71)
at io.reactivex.Flowable.subscribe(Flowable.java:14479)
at io.reactivex.Flowable.subscribe(Flowable.java:14416)
at io.reactivex.Flowable.subscribe(Flowable.java:14337)
at org.web3j.sample.SubscribeMainnet.runFilter(SubscribeMainnet.java:69)
at org.web3j.sample.SubscribeMainnet.main(SubscribeMainnet.java:42)
Caused by: java.io.IOException: Request with id 0 timed out
at org.web3j.protocol.websocket.WebSocketService.lambda$setRequestTimeout$32(WebSocketService.java:174)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:844)