How to get balance of all accounts in ethereum network using javascript?

–1 vote

I have created a set of accounts in private ethereum networks. I am able to check the balance of all these accounts using the following command:

> checkAllBalances();

I have created a web page that will display the balance of all the accounts on the click of a button. So, I want to write a javascript to list the balances. Any ideas on how to do it?

Jan 9 in Blockchain by digger
• 26,550 points
61 views

1 answer to this question.

0 votes

You can write a function that will fetch the account balance using the  eth.getBalance() method. Refer the below code:

function checkAllBalances() { 
var i = 0; 
eth.accounts.forEach( function(e){
     console.log("eth.accounts["+i+"]: " + e + " \tbalance: " + web3.fromWei(eth.getBalance(e), "ether") + " ether"); 
i++; 
})
};

answered Jan 9 by Omkar
• 67,620 points

Related Questions In Blockchain

0 votes
1 answer

How to get all address and send ethers in solidity using a loop?

I found a similar code somewhere: contract  Holders{ uint ...READ MORE

answered Jul 31, 2018 in Blockchain by digger
• 26,550 points
197 views
0 votes
1 answer

How to get the number of tokens in the Bitcoin network?

This information can easily be calculated by ...READ MORE

answered Aug 31, 2018 in Blockchain by Christine
• 15,790 points
30 views
0 votes
1 answer

How do I get the balance of an account in Ethereum?

On the Web: (Not programmatic, but for completeness...) ...READ MORE

answered Nov 14, 2018 in Blockchain by Perry
• 17,020 points
179 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
155 views
0 votes
1 answer
0 votes
0 answers

Error: Unexpected token o in JSON at position 1

I have been working with Interacting a ...READ MORE

Mar 6 in Blockchain by saeedi
• 120 points

edited Mar 6 by Omkar 425 views
0 votes
1 answer

How to get IP address of peer connected in private ethereum network?

To get these details, you can use ...READ MORE

answered Jan 10 in Blockchain by Omkar
• 67,620 points
55 views
0 votes
1 answer

How to get account with ethers by default in ethereum private network?

Have you created an account before allocating ...READ MORE

answered Jan 9 in Blockchain by Omkar
• 67,620 points
51 views