以太坊常见问题和错误

如何在Java文件中创建以太坊帐户和通过web3j查询账目情况?

在web3j的文档中,我没有看到创建帐户和的web3j查询账目任何内容,我想知道这是否可行?

问题回答:

其实挺简单的,ethGetBalance方法将返回任何给定帐户的余额。你可以参考下面的例子:

// connect to node
Web3j web3 = Web3j.build(new HttpService());  // defaults to http://localhost:8545/

// send asynchronous requests to get balance
EthGetBalance ethGetBalance = web3
  .ethGetBalance("0xAccountAddress", DefaultBlockParameterName.LATEST)
  .sendAsync()
  .get();

BigInteger wei = ethGetBalance.getBalance();