7

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
8

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();
  • 1
    If web3j is built with remote node. And i provide a invalid wallet address what will the getBalance return. – Najeebullah Shah Aug 20 '17 at 7:35
3

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.

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.