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 10, 2019 in Blockchain by digger
• 26,740 points
2,167 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 10, 2019 by Omkar
• 69,210 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,740 points
2,555 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
867 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 15, 2018 in Blockchain by Perry
• 17,100 points
16,777 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
1,708 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,241 views
0 votes
0 answers

Error: Unexpected token o in JSON at position 1

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

Mar 6, 2019 in Blockchain by saeedi
• 120 points

edited Mar 6, 2019 by Omkar 2,214 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, 2019 in Blockchain by Omkar
• 69,210 points
2,842 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, 2019 in Blockchain by Omkar
• 69,210 points
1,509 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP