如何连接bsc测试网络和本地主机:8545
这是我的装载合同代码
PerformanceToken contract = PerformanceToken.load(
this.contractAddress, web3j, transactionManager, new StaticGasProvider(this.gasPrice, DefaultGasProvider.GAS_LIMIT));首先,我使用了草帽启动本地主机节点,我的配置是
web3j:
enable: true
nodeService: http://127.0.0.1:8545
chainId: 31337但它不能用扔
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' 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网络,这是我的配置
web3j:
enable: true
nodeService: https://data-seed-prebsc-1-s1.binance.org:8545
chainId: 97但它也不能用,特劳
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 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);
}
}现在我很困惑,不能再做下去了,所以请帮帮我。这是github web3j问题
发布于 2021-10-15 01:13:33
我的错,我使用springboot yaml配置,0x开始字符串将转换为数字,所以这是我的配置错误,应该是
web3j:
contractAddress: "0x81cE80b17eAddB5A9938461C07fd9F45c87B97d2"不
web3j:
contractAddress: 0x81cE80b17eAddB5A9938461C07fd9F45c87B97d2https://ethereum.stackexchange.com/questions/111428
复制相似问题