How do I initially connect to Ethereum Network in Android using EthereumJ? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How do I initially connect to Ethereum Network in Android using EthereumJ? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I want to write an Android Ethereum Wallet with which I want to make transactions. However, I have not been able to fully figure out how to connect to the Ethereum Network using EthereumJ.

From the research I’ve done, many people use geth to initiate a node, however this did not work for me because I want to make an android app where this is either not supported or I couldn’t figure out how to implement it. Currently, I’m trying the below code and am trying to use a light node (so no full sync when connecting) to connect to the Ethereum network:

private void connectToEthNetwork() {
    SysPropConfig.props = new SystemProperties();
    SysPropConfig.props.overrideParams("sync.enabled", "false");
    Ethereum ethereum = EthereumFactory.createEthereum(SysPropConfig.class);
}

@Configuration
@NoAutoscan
public static class SysPropConfig {
    static SystemProperties props;

    @Bean
    public SystemProperties systemProperties() {
        return props;
    }
}

I’d prefer a solution that does not use any external APIs that require keys to use (like Infura for example). I hope you guys can help, thank you in advance for your assistance!

Answer

I figured it out by using the go-ethereum android library:

    NodeConfig nc = Geth.newNodeConfig();
    try {
        Node node = Geth.newNode(getFilesDir() + "/.ethNode", nc);
        node.start();
        Thread.sleep(5000);
    }
    catch (Exception e){
    // Do something
    }

Hope this helps somebody!

We are here to answer your question about How do I initially connect to Ethereum Network in Android using EthereumJ? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji