hyperledger-web3j / web3j

Lightweight Java and Android library for integration with Ethereum clients
https://www.web3labs.com/web3j-sdk
Other
5.12k stars 1.69k forks source link

Infura WS and ethGasPrice() method leads to invalid response received #1221

Closed dfsantamaria closed 4 years ago

dfsantamaria commented 4 years ago

Whit an Infura WS node, a call to web3j method ethGasPrice() leads to the error org.web3j.protocol.exceptions.ClientConnectionException: Invalid response received: 404; 404 page not found

Method ethGasPrice() works with an Infura HTTPS node. I'm using web3j 5.0.0.

dfsantamaria commented 4 years ago

The problem seems to have a deep cause. Trying

` Web3j web3j = Web3j.build(new HttpService(the_ws_service));

ReadonlyTransactionManager roTransactionManager = new ReadonlyTransactionManager(web3j, the_address);
ContractGasProvider gasProvider = new DefaultGasProvider();
TheContract contract = TheContract.load(the_address, web3j,roTransactionManager, gasProvider);
  try 
  {
      contract.amethod().send();
  } 
  catch (Exception ex) {
      Logger.getLogger(InfuraWSTest.class.getName()).log(Level.SEVERE, null, ex);
  }`

leads to:

org.web3j.protocol.exceptions.ClientConnectionException: Invalid response received: 404; 404 page not found

    at org.web3j.protocol.http.HttpService.performIO(HttpService.java:173)
    at org.web3j.protocol.Service.send(Service.java:48)
    at org.web3j.protocol.core.Request.send(Request.java:87)
    at org.web3j.tx.ReadonlyTransactionManager.sendCall(ReadonlyTransactionManager.java:70)
    at org.web3j.tx.ManagedTransaction.call(ManagedTransaction.java:134)
    at org.web3j.tx.Contract.executeCall(Contract.java:292)
    at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:300)
    at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:311)
    at org.web3j.tx.Contract.lambda$executeRemoteCallSingleValueReturn$1(Contract.java:397)
    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
    at main.InfuraWSTest.main(InfuraWSTest.java:33)

in line contract.amethod().send();

dfsantamaria commented 4 years ago

Wrong usage of web socket in the code.