Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

17.7. 獲得以太坊狀態信息

17.7.1. 獲取客戶端版本

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

17.7.2. 協議版本

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

17.7.3. 查看當前區塊

			
			EthBlockNumber ethBlockNumber = web3j.ethBlockNumber().send();
			BigInteger blockNumber = ethBlockNumber.getBlockNumber();
			System.out.println("當前區塊:" + blockNumber);			
			
			

17.7.4. 同步狀態

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

17.7.5. 挖礦狀態

			
			EthMining ethMining = web3j.ethMining().send();
			boolean isMining = ethMining.isMining();
			System.out.println("挖礦狀態:" + isMining);
			
			

17.7.6. 礦工賬號

			
			EthCoinbase ethCoinbase = web3j.ethCoinbase().send();
			String coinbase = ethCoinbase.getAddress();
			System.out.println("礦工賬號:" + coinbase);
			
			

17.7.7. 挖礦速度

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

17.7.8. Gas 價格

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

17.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));
			
			

17.7.10. 節點數量

			
			NetPeerCount netPeerCount = web3j.netPeerCount().send();
			BigInteger peerCount = netPeerCount.getQuantity();
			System.out.println("節點數量:" + peerCount);