首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >web3j无法连接本地主机或bsc网络

web3j无法连接本地主机或bsc网络
EN

Ethereum用户
提问于 2021-10-12 06:23:15
回答 1查看 378关注 0票数 1

Issue_title

如何连接bsc测试网络和本地主机:8545

Issue_description

这是我的装载合同代码

代码语言:javascript
复制
 PerformanceToken contract = PerformanceToken.load(
                this.contractAddress, web3j, transactionManager, new StaticGasProvider(this.gasPrice, DefaultGasProvider.GAS_LIMIT));

首先,我使用了草帽启动本地主机节点,我的配置是

代码语言:javascript
复制
web3j:
  enable: true
  nodeService: http://127.0.0.1:8545
  chainId: 31337

但它不能用扔

代码语言:javascript
复制
Caused by: org.web3j.ens.EnsResolutionException: Unable to determine sync status of node
    at org.web3j.ens.EnsResolver.obtainPublicResolver(EnsResolver.java:78)
    at org.web3j.ens.EnsResolver.resolve(EnsResolver.java:88)
    at org.web3j.tx.Contract.resolveContractAddress(Contract.java:720)
    at org.web3j.tx.Contract.<init>(Contract.java:102)
    at org.web3j.tx.Contract.<init>(Contract.java:84)
    at com.shangchain.web3j.contract.PerformanceToken.<init>(PerformanceToken.java:134)
    at com.shangchain.web3j.contract.PerformanceToken.load(PerformanceToken.java:561)
    at com.shangchain.web3j.client.Web3jClient.loadPerformanceToken(Web3jClient.java:58)
    at com.shangchain.web.controller.bsc.BscController.<init>(BscController.java:27)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)
    ... 24 common frames omitted
Caused by: org.web3j.ens.EnsResolutionException: Node is not currently synced
    at org.web3j.ens.EnsResolver.obtainPublicResolver(EnsResolver.java:73)
    ... 37 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:58999', transport: 'socket'
代码语言:javascript
复制
   boolean isSynced() throws Exception {
        EthSyncing ethSyncing = web3j.ethSyncing().send();
        if (ethSyncing.isSyncing()) {
            return false;
        } else {
            EthBlock ethBlock =
                    web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send();
            long timestamp = ethBlock.getBlock().getTimestamp().longValueExact() * 1000;

            return System.currentTimeMillis() - syncThreshold < timestamp;
        }
    }

然后我转到bsc网络,这是我的配置

代码语言:javascript
复制
web3j:
  enable: true
  nodeService: https://data-seed-prebsc-1-s1.binance.org:8545
  chainId: 97

但它也不能用,特劳

代码语言:javascript
复制
Caused by: org.web3j.ens.EnsResolutionException: Unable to determine sync status of node
    at org.web3j.ens.EnsResolver.obtainPublicResolver(EnsResolver.java:78)
    at org.web3j.ens.EnsResolver.resolve(EnsResolver.java:88)
    at org.web3j.tx.Contract.resolveContractAddress(Contract.java:720)
    at org.web3j.tx.Contract.<init>(Contract.java:102)
    at org.web3j.tx.Contract.<init>(Contract.java:84)
    at com.shangchain.web3j.contract.PerformanceToken.<init>(PerformanceToken.java:134)
    at com.shangchain.web3j.contract.PerformanceToken.load(PerformanceToken.java:561)
    at com.shangchain.web3j.client.Web3jClient.loadPerformanceToken(Web3jClient.java:58)
    at com.shangchain.web.controller.bsc.BscController.<init>(BscController.java:27)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)
    ... 24 common frames omitted
Caused by: org.web3j.ens.EnsResolutionException: Unable to resolve ENS registry contract for network id: 97
    at org.web3j.ens.Contracts.resolveRegistryContract(Contracts.java:33)
    at org.web3j.ens.EnsResolver.lookupResolver(EnsResolver.java:140)
    at org.web3j.ens.EnsResolver.obtainPublicResolver(EnsResolver.java:75)
    ... 37 common frames omitted
代码语言:javascript
复制
    public static String resolveRegistryContract(String chainId) {
        final Long chainIdLong = Long.parseLong(chainId);
        if (chainIdLong.equals(ChainIdLong.MAINNET)) {
            return MAINNET;
        } else if (chainIdLong.equals(ChainIdLong.ROPSTEN)) {
            return ROPSTEN;
        } else if (chainIdLong.equals(ChainIdLong.RINKEBY)) {
            return RINKEBY;
        } else {
            throw new EnsResolutionException(
                    "Unable to resolve ENS registry contract for network id: " + chainId);
        }
    }

Issue_context

现在我很困惑,不能再做下去了,所以请帮帮我。这是github web3j问题

EN

回答 1

Ethereum用户

发布于 2021-10-15 01:13:33

我的错,我使用springboot yaml配置,0x开始字符串将转换为数字,所以这是我的配置错误,应该是

代码语言:javascript
复制
web3j:
  contractAddress: "0x81cE80b17eAddB5A9938461C07fd9F45c87B97d2"

代码语言:javascript
复制
web3j:
  contractAddress: 0x81cE80b17eAddB5A9938461C07fd9F45c87B97d2
票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

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

复制
相关文章

相似问题

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