Home | 简体中文 | 繁体中文 | 杂文 | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | Github | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

11.7. 获得以太坊状态信息

11.7.1. 获取客户端版本

			
			Web3ClientVersion web3ClientVersion = web3j.web3ClientVersion().send();
			String clientVersion = web3ClientVersion.getWeb3ClientVersion();
			System.out.println("客户端版本: " + clientVersion);			
			
			

11.7.2. 协议版本

			
			EthProtocolVersion ethProtocolVersion = web3j.ethProtocolVersion().send();
			String protocolVersion = ethProtocolVersion.getProtocolVersion();
			System.out.println("协议版本" + protocolVersion);
			
			

11.7.3. 查看当前区块

			
			EthBlockNumber ethBlockNumber = web3j.ethBlockNumber().send();
			BigInteger blockNumber = ethBlockNumber.getBlockNumber();
			System.out.println("当前区块:" + blockNumber);			
			
			

11.7.4. 同步状态

			
			EthSyncing ethSyncing = web3j.ethSyncing().send();
			boolean isSyncing = ethSyncing.isSyncing();
			System.out.println("同步状态:" + isSyncing);
			
			

11.7.5. 挖矿状态

			
			EthMining ethMining = web3j.ethMining().send();
			boolean isMining = ethMining.isMining();
			System.out.println("挖矿状态:" + isMining);
			
			

11.7.6. 矿工账号

			
			EthCoinbase ethCoinbase = web3j.ethCoinbase().send();
			String coinbase = ethCoinbase.getAddress();
			System.out.println("矿工账号:" + coinbase);
			
			

11.7.7. 挖矿速度

			
			EthHashrate ethHashrate = web3j.ethHashrate().send();
			BigInteger hashRate = ethHashrate.getHashrate();
			System.out.println("挖矿速度:" + hashRate);
			
			

11.7.8. Gas 价格

			
			EthGasPrice ethGasPrice = web3j.ethGasPrice().send();
			BigInteger gasPrice = ethGasPrice.getGasPrice();
			System.out.println("Gas 价格:" + gasPrice);
			
			

11.7.9. 评估GAS

			
	EthEstimateGas ethEstimateGas = web3.ethEstimateGas(Transaction.createEthCallTransaction(credentials.getAddress(), null, encodedFunction)).sendAsync().get();
	BigInteger estimateGas = ethEstimateGas.getAmountUsed();
	System.out.println(estimateGas);			
	
    ethEstimateGas.getAmountUsed().divide(BigInteger.valueOf(100));
			
			

11.7.10. 节点数量

			
			NetPeerCount netPeerCount = web3j.netPeerCount().send();
			BigInteger peerCount = netPeerCount.getQuantity();
			System.out.println("节点数量:" + peerCount);