TransWikia.com

Issues sending Ether with web3j

Ethereum Asked by chinedu on December 4, 2021

Hello guys I have search around but no reasonable explanation as to why i would get these exceptions, I have already requested and have 3 ethers with associated with my address. Here is my code for sending ether:

private static void transferEther(String password)
            throws IOException, CipherException, InterruptedException, TransactionException {
        Web3j web3 = Web3j.build(new HttpService("https://rinkeby.infura.io/v1/<API-KEY>"));

    Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().send();
    String clientVersion = web3ClientVersion.getWeb3ClientVersion();
    System.out.println("Connected to Ethereum client version: " + clientVersion);

    Credentials credentials = WalletUtils.loadCredentials(password,
            new File("/PATH_TO_FILE/"
                    + "UTC--2018-12-12T07-39-27.54000000Z--ff1062eb9f9f4369780f8029fe60a5825eb943c9.json")
                            .toString());

    RemoteCall<TransactionReceipt> transactionReceipt = Transfer.sendFunds(web3, credentials,
            "ADDRESS", BigDecimal.valueOf(0.2), Convert.Unit.ETHER);

    System.out.println("Funds transfer completed, transaction hash: " + transactionReceipt.toString());
}

but i get the following exceptions:

Exception in thread "main" java.lang.NoClassDefFoundError:
rx/schedulers/Schedulers at
org.web3j.protocol.rx.JsonRpc2_0Rx.(JsonRpc2_0Rx.java:39) at
org.web3j.protocol.core.JsonRpc2_0Web3j.(JsonRpc2_0Web3j.java:87)
at
org.web3j.protocol.core.JsonRpc2_0Web3j.(JsonRpc2_0Web3j.java:80)
at org.web3j.protocol.Web3j.build(Web3j.java:21) at
CreateWallet.transferEther(CreateWallet.java:51) at
CreateWallet.main(CreateWallet.java:81) Caused by:
java.lang.ClassNotFoundException: rx.schedulers.Schedulers at
java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) … 6 more

One Answer

In case anyone had this problem I found the solution. It was simply a proxy problem and missing library problem.

  1. add the rxJava ,okio and Okhttp jar lib.

  2. This step is optional if u have a proxy problem like i did.

    String hostname = "IP ADDRESS";
    int port = PORT;
    
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(hostname, port));
    OkHttpClient client = new OkHttpClient.Builder().proxy(proxy).build();
    
    String url = "https://rinkeby.infura.io/v3/<API-KEY>";
    
    web3 = Web3j.build(new HttpService(url, client, true));
    

Answered by chinedu on December 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP