我最初如何使用以太坊J连接到Android中的以太坊网络



我想写一个安卓以太坊钱包,我想用它来进行交易。但是,我还没有完全弄清楚如何使用以太坊连接到以太坊网络。

根据我所做的研究,许多人使用 geth 来启动节点,但这对我不起作用,因为我想制作一个不支持或我不知道如何实现它的 android 应用程序。目前,我正在尝试以下代码,并尝试使用轻节点(因此连接时没有完全同步)连接到以太坊网络:

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;
    }
}

我更喜欢不使用任何需要使用密钥的外部 API 的解决方案(例如 Infura)。希望大家能帮忙,提前感谢大家的帮助!

我通过使用go-ethereum android库想通了:

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

希望这对某人有所帮助!

最新更新