Skip to content

web3sdk debug

yanyanho edited this page Jan 7, 2019 · 4 revisions

检查步骤

  1. 检查sdk的连接配置“[email protected]:30333”是否配置成,连接节点的channelPort--channelport的配置在节点的config.json配置文件中。
  2. 节点配置config.json中listenip配置是否正确,最好直接监听0.0.0.0。
config.json

{
    "sealEngine":"PBFT",
    "systemproxyaddress":"0x6d6fdda882bc90253464971ca56eb158c6a7bf1b",
    "listenip":"10.107.105.59",
    "cryptomod":"0",
    "rpcport":"8315",
    "p2pport":"30805",
    "channelPort":"30806",
  1. ps -ef检查节点进程是否启动,netstat -anp检查进程是否监听了channelport端口。
  2. 检查channelPort是否能telnet通,需要能telnet通。如果不通检查网络策略。
  3. 查看sdk的日志,相关日志的配置在log4j2.xml
  4. sdk的ca.crt必须要能校验节点的节点证书(node.crt/server.crt),也就是颁发节点证书的ca证书,或证书链(如果是多级的话)。如果ca.crt错误,sdk的日志会出现:unable to find valid certification path to requested target
  5. FISCO-BCOS中client.keystore 的生成方法
  6. 如果上面还是没有解决问题,可尝试增大连接建立等待时间,相关配置在applicationContext.xml中channelService的connectSeconds配置项
applicationContext.xml

<bean id="channelService" class="org.bcos.channel.client.Service"> 
		<property name="orgID" value="WB" />
		<property name="connectSeconds" value="10" />
		<property name="connectSleepPerMillis" value="10" />
  1. 在使用web3sdk进行合约部署,和发送交易时,需要设置future超时时间,例如。
Ok okDemo = Ok.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get(60000, TimeUnit.MILLISECONDS);
if (okDemo != null) {
	while (true) {
		System.out.println("####contract address is: " + okDemo.getContractAddress());
		TransactionReceipt receipt = okDemo.trans(new Uint256(4)).get(60000, TimeUnit.MILLISECONDS);
		System.out.println("###callback trans success");
		Uint256 toBalance = okDemo.get().get(60000, TimeUnit.MILLISECONDS);
		System.out.println("============to balance:" + toBalance.getValue());
		Thread.sleep(1000);
	}
}

日志中常见错误信息(在web3sdk的log4j2.xml中配置)

  1. unable to find valid certification path to requested target :ca.crt证书错误,验证不了节点证书
  2. java.lang.IllegalArgumentException: keyCertChain contains null entry :clinet.keystore中没有alias为client的sdk证书
  3. java.security.UnrecoverableKeyException: Password verification failed :clinet.keystore密码错误
  4. {"error":{"code":0,"data":null,"message":"NoCallPermission."},"id":1,"jsonrpc":"2.0"} :调用合约权限错误
  5. {"error":{"code":0,"data":null,"message":"NoDeployPermission ."},"id":1,"jsonrpc":"2.0"} :没有合约部署权限
  6. java.io.IOException: activeConnections isEmpty :没有可用连接,请用上面的检查步骤检查
  7. java.io.FileNotFoundExcetion: class path resource [ca.crt] cannot be resolved to absolute file path because it does not reside in the file system....... 请把application.xml中配置修改成
Clone this wiki locally