#!/usr/bin/env node
const Web3 = require('web3.js-thk');
const bip39 = require('bip39');
const HDWallet = require('ethereum-hdwallet')
const utils = require('ethereumjs-util');
const fs = require('fs');
const web3 = new Web3();
const rpxUrl = "http://rpctest.chainopen.cn"
web3.setProvider(new web3.providers.HttpProvider(rpxUrl));

const mnemonic = fs.readFileSync(".secret").toString().trim();

const getPrivateKey = async (mnemonic,n) => {
    const seed = await bip39.mnemonicToSeed(mnemonic.trim())
    const hdwallet = HDWallet.fromSeed(seed)
    const privateKey = hdwallet.derive('m/44\'/60\'/0\'/0/'+n).getPrivateKey();
    const address = utils.privateToAddress((privateKey))
    var account = web3.thk.GetAccount('1', '0x'+address.toString('hex'));
    var balance = account.balance;
    console.log("0x"+privateKey.toString('hex'),":","0x"+address.toString('hex'),"("+web3.fromWei(balance,'ether')+" ether)")
}
for(var i=0;i<10;i++){
    getPrivateKey(mnemonic,i);
}

