geth JavaScript Version

The following geth JavaScript will list a block of accounts, both used and unused, from your Ledger Nano S:

// ----------------------------------------------------------------------------- // List accounts from the Ledger Nano S // // (c) BokkyPooBah - Aug 13 2017. The MIT Licence. // ----------------------------------------------------------------------------- function padLeft(s, n) { var result = s.toString(); while (result.length < n) { result = " " + result; } return result; } function listNanoAccounts(from, to) { if (from == null) { from = 0; } if (to == null) { to = 9; } var nanoUrl=personal.listWallets[personal.listWallets.length-1].url; var nanoPathPrefix="m/44'/60'/0'/"; var total = new BigNumber(0); console.log(" # Account Ethers"); console.log("--- ------------------------------------------ --------------------------"); for (var i = from; i <= to; i++) { var account = personal.deriveAccount(nanoUrl, nanoPathPrefix + i, true).address; var weis = eth.getBalance(account); var balance = web3.fromWei(weis, "ether"); total = total.add(balance); console.log(padLeft(i, 3) + " " + account + " " + padLeft(balance.toFixed(18), 26)); } console.log("--- ------------------------------------------ --------------------------"); console.log(" Total " + padLeft(total, 26)); console.log("--- ------------------------------------------ --------------------------"); } listNanoAccounts()





Command Line Script Option

The script above can be modified to be run from the command line:

# ------------------------------------------------------------------------------ # List accounts from the Ledger Nano S # # Works in OS/X and Linux. May work in Windows with Cygwin. # # How to use: # 1. Save into a file, e.g., ~/bin/getNanoAccounts # 2. Set the executable bit - `chmod 700 ~/bin/getNanoAccounts` # 3. Run the script - `~/bin/getNanoAccounts` # # (c) BokkyPooBah - Aug 13 2017. The MIT Licence. # ------------------------------------------------------------------------------ geth attach << EOF | grep "RESULT: " | sed "s/RESULT: //" function padLeft(s, n) { var result = s.toString(); while (result.length < n) { result = " " + result; } return result; } function listNanoAccounts(from, to) { if (from == null) { from = 0; } if (to == null) { to = 9; } var nanoUrl=personal.listWallets[personal.listWallets.length-1].url; var nanoPathPrefix="m/44'/60'/0'/"; var total = new BigNumber(0); console.log("RESULT: # Account Ethers"); console.log("RESULT: --- ------------------------------------------ --------------------------"); for (var i = from; i <= to; i++) { var account = personal.deriveAccount(nanoUrl, nanoPathPrefix + i, true).address; var weis = eth.getBalance(account); var balance = web3.fromWei(weis, "ether"); total = total.add(balance); console.log("RESULT: " + padLeft(i, 3) + " " + account + " " + padLeft(balance.toFixed(18), 26)); } console.log("RESULT: --- ------------------------------------------ --------------------------"); console.log("RESULT: Total " + padLeft(total, 26)); console.log("RESULT: --- ------------------------------------------ --------------------------"); } listNanoAccounts() EOF





Following is some sample output:

Iota:bin bokkypoobah$ ~/bin/getNanoAccounts # Account Ethers --- ------------------------------------------ -------------------------- 0 0x1234567890000000000000000000000000000000 1.111111111111111111 1 0x1234567891111111111111111111111111111111 2.222222222222222222 2 0x1234567891111111111111111111111111111112 0.000000000000000000 3 0x1234567891111111111111111111111111111113 0.000000000000000000 4 0x1234567891111111111111111111111111111114 0.000000000000000000 5 0x1234567891111111111111111111111111111115 0.000000000000000000 6 0x1234567891111111111111111111111111111116 0.000000000000000000 7 0x1234567891111111111111111111111111111117 0.000000000000000000 8 0x1234567891111111111111111111111111111118 0.000000000000000000 9 0x1234567891111111111111111111111111111119 0.000000000000000000 --- ------------------------------------------ -------------------------- Total 3.333333333333333333 --- ------------------------------------------ --------------------------





See also How do I print my account balances and TheDAO tokens from geth which can be extended to any ERC20 tokens.