Web3j – How to Create Accounts and Retrieve Ether Balance in Java File

web3j

I do not see anything in creating accounts and retrieving ether balance in web3j's documentation, I wonder if it is possible.

Best Answer

The "ethGetBalance" method will return the balance of any given account. Pls see example below:

// 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();