1.查询ETH钱包余额:
private static final String URL = “http://127.0.0.1:8545/”;
Web3j web3 = Web3j.build(new HttpService(URL));
EthGetBalance ethGetBalance = null;
try {
// 通过账户地址查询余额
ethGetBalance = web3j
.ethGetBalance(“0xac***f0261bc4b0*0d5e23d9f80d24bf89fe”, DefaultBlockParameterName.LATEST)
.sendAsync()
.get();
} catch (Exception e) {
throw new Exception(“查询钱包余额失败”);
}
1eth = 10e18 wei
单位转换:
BigDecimal banlance = Convert.fromWei(ethGetBalance.getBalance().toString(), Convert.Unit.ETHER);
- 通过钱包密码和助记词找回私钥公钥
通过密码与助记词获得钱包地址、公钥及私钥信息
Credentials credentials = WalletUtils.loadBip39Credentials(walletPwd, memorizingWords);
//公钥16进制字符串表示
String publicKey = credentials.getEcKeyPair().getPublicKey().toString(16);
//私钥16进制字符串表示
String pr