Search in sources :

Example 1 with Web3ClientVersion

use of org.bcos.web3j.protocol.core.methods.response.Web3ClientVersion in project web3sdk by FISCO-BCOS.

the class WalletSendFunds method getEthereumClient.

private Web3j getEthereumClient() {
    String clientAddress = console.readLine("Please confirm address of running Ethereum client you wish to send " + "the transfer request to [" + HttpService.DEFAULT_URL + "]: ").trim();
    Web3j web3j;
    if (clientAddress.equals("")) {
        web3j = Web3j.build(new HttpService());
    } else if (clientAddress.contains("infura.io")) {
        web3j = Web3j.build(new InfuraHttpService(clientAddress));
    } else {
        web3j = Web3j.build(new HttpService(clientAddress));
    }
    try {
        Web3ClientVersion web3ClientVersion = web3j.web3ClientVersion().sendAsync().get();
        if (web3ClientVersion.hasError()) {
            exitError("Unable to process response from client: " + web3ClientVersion.getError());
        } else {
            console.printf("Connected successfully to client: %s%n", web3ClientVersion.getWeb3ClientVersion());
            return web3j;
        }
    } catch (InterruptedException | ExecutionException e) {
        exitError("Problem encountered verifying client: " + e.getMessage());
    }
    throw new RuntimeException("Application exit failure");
}
Also used : InfuraHttpService(org.bcos.web3j.protocol.infura.InfuraHttpService) Web3j(org.bcos.web3j.protocol.Web3j) HttpService(org.bcos.web3j.protocol.http.HttpService) InfuraHttpService(org.bcos.web3j.protocol.infura.InfuraHttpService) Web3ClientVersion(org.bcos.web3j.protocol.core.methods.response.Web3ClientVersion) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 Web3j (org.bcos.web3j.protocol.Web3j)1 Web3ClientVersion (org.bcos.web3j.protocol.core.methods.response.Web3ClientVersion)1 HttpService (org.bcos.web3j.protocol.http.HttpService)1 InfuraHttpService (org.bcos.web3j.protocol.infura.InfuraHttpService)1