首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EthereumJ连接到专用节点

EthereumJ连接到专用节点
EN

Ethereum用户
提问于 2017-07-20 07:24:24
回答 2查看 244关注 0票数 0

我需要用没有ethereum.conf文件的ethereumj连接到私有的ethereum节点。我需要使用从代码中配置connect。

EN

回答 2

Ethereum用户

发布于 2017-07-26 11:56:37

对我来说很管用。也许它会对某些人有帮助。

代码语言:javascript
复制
public class EthereumAppConfig implements BeanPostProcessor {

    private static final List<String> ipList = new ArrayList<>();

    private static ConfigValue value(Object value) {
        return ConfigValueFactory.fromAnyRef(value);
    }





    @Override
    public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
        if (o instanceof SystemProperties)
            ((SystemProperties) o).overrideParams(getConfig());

        return o;
    }

    @Override
    public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
        return o;
    }








    private static Config getConfig() {
        ipList.add("0.0.0.0:00000");
        List<Map<String, String>> peerActives = new ArrayList<>();


        Map<String, String> urls = new HashMap<>();

        urls.put("url", "enode://0");
        urls.put("url", "enode://1");
        urls.put("url", "enode://2");
        urls.put("url", "enode://4");

        peerActives.add(
                urls
        );
        return ConfigFactory.empty()
                .withValue("peer.discovery.enabled", value(true))
                .withValue("peer.discovery.external.ip", value("0.0.0.0"))
                .withValue("peer.discovery.bind.ip", value("0.0.0.0"))
                .withValue("peer.discovery.persist", value("false"))
                .withValue("peer.listen.port", value(00000))
                .withValue("peer.privateKey", value(Hex.toHexString(ECKey.fromPrivate(("0").getBytes()).getPrivKeyBytes())))
                .withValue("peer.networkId", value(76543))
                .withValue("sync.enabled", value(true))
                .withValue("genesis", value("genesis.json"))
                .withValue("database.dir", value("database"))
                .withValue("peer.discovery.ip.list", value(ipList))
                .withValue("peer.active", value(peerActives))
                .withValue("mine.start", value(true));
    }

}
票数 0
EN

Ethereum用户

发布于 2017-11-08 00:09:10

请查看我已经上传到Github的代码,它正是这样做的:)它在.conf文件中包含了所有相关的配置。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/21642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档