2

I have been trying to observe the transactions taking place on mainnet for a specific contract, specifically Tether (USDT). I am able to download the contract and compile the solidity code with Web3 (Java). However I am unable to subscribe for transfer events. It just times out.. is there something I am missing? I am using the below code but get a timeout.

I can see no reason why this would not work, I connect through Infura via wss://mainnet.infura.io/ws/v3/<my_identifier_here>

  TetherToken tetherToken = TetherToken.load(
     "0xdac17f958d2ee523a2206206994597c13d831ec7",
     session.getWeb3(),
     session.getCredentials(),
     session.getGasProvider());

  String symbol = tetherToken.symbol().send();
  String name = tetherToken.name().send();
  BigInteger decimal = tetherToken.decimals().send();

  System.out.println("symbol: " + symbol); // success = USDT
  System.out.println("name: " + name); // success = Tether USD
  System.out.println("decimal: " + decimal.intValueExact()); // success = 6

  // java.io.IOException: Request with id 5 timed out
  tetherToken.transferEventFlowable(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST)
     .subscribe(event -> {
           try {
              System.err.printf("hash=%s from=%s to=%s amount=%s%n",
                 event.log.getTransactionHash(),
                 event.from,
                 event.to,
                 event.value);
           }catch(Throwable e) {
              e.printStackTrace();
           }
        });

Any help would be greatly appreciated.

1 Answers1

2

Turns out the Web3j framework hides an issue with Infura responses. If the result of the eth log filter is > 10000 results then Infura responds with:

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32005,
    "message": "query returned more than 10000 results"
  }
}
  • Your question & answer put me on the right track. I was wondering why my connection timed out, turns out it was exactly this. Using DefaultBlockParameterName.EARLIEST isn't such a great idea if you want to listen to events flowing by in the first place. Thanks a lot. If I may ask, where did you find information on how to compile the downloaded JSON into the ABI? – Johannes Jander Jun 06 '20 at 18:41