Skip to main content

Sample Java Script

JavaScript Add-ons

In order to use the scripts, paste them in your Energi Core Node console:

Account(s) balance

function checkAllBalances() {
var totalBal = 0;
for (var acctNum in eth.accounts) {
var acct = eth.accounts[acctNum];
var acctBal = web3.fromWei(eth.getBalance(acct), "ether");
totalBal += parseFloat(acctBal);
console.log(" eth.accounts[" + acctNum + "]: \t" + acct + " \tbalance: " + acctBal + " NRG");
}
console.log(" Total balance: " + totalBal + " NRG");
return true;
};
function checkBalance(acct) {
var acctBal = web3.fromWei(eth.getBalance(acct), "ether");
console.log(" account:\t" + acct + " \tbalance: " + acctBal + " NRG");
return true;
};

Once the scripts are added, you can run them by typing:

checkBalance(your_address) or checkAllBalances()

danger

The scripts are stored in memory and are active for the session. If you exit the node, you will have to re-enter them.

Masternode's balance

function mnBalances() {
var totalBal = 0;
for (var acctNum in eth.accounts) {
var acct = eth.accounts[acctNum];
var acctBal = web3.fromWei(masternode.masternodeInfo(acct).collateral, "ether");
totalBal += parseFloat(acctBal);
console.log(" mn.accounts[" + acctNum + "]: \t" + acct + " \tbalance: " + acctBal + " NRG");
}
console.log(" Total balance: " + totalBal + " NRG");
return true;
};