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

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!

Leave a Reply

Your email address will not be published. Required fields are marked *