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

  • look at their github wiki
    – Sig Touri
    Jun 6 '17 at 18:53

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)

BigInteger wei = ethGetBalance.getBalance();
  • 1
    If web3j is built with remote node. And i provide a invalid wallet address what will the getBalance return. Aug 20 '17 at 7:35

You can use CURL command or use request module inside your code to call create account API -

CURL command for your reference:

curl -X POST --data '{"jsonrpc":"2.0","method":"personal_newAccount","params":["pass"],"id":74}' http://localhost:8545

Also, you must run the geth node with the "personal" api enabled to make this method available:

geth --rpc --rpcapi "personal,eth,web3"

To check account balance using web3js, use following command -

web3.eth.getBalance('account address hash in quotes')

Hope this helps.

  • this is in correct the question is about web3j and how to get it using java
    – Abdullah
    Feb 17 '20 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.