-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtestrpc.js
48 lines (41 loc) · 1.27 KB
/
testrpc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const testrpc = require('ethereumjs-testrpc')
const hdkey = require('ethereumjs-wallet/hdkey');
const bip39 = require('bip39');
const ACCOUNTFUNDING = '0x33B2E3C9FD0804000000000'; // One billion Ether in Wei
const HDPATH = 'm/44\'/60\'/0\'/0/';
const mnemonic = "economy chuckle twin square rose provide friend combine fashion wheel purse huge"
let accounts = [];
function generateAccounts(mnemonic, hdPathIndex, totalToGenerate, accumulatedAddrs) {
const hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic));
const node = hdwallet.derivePath(HDPATH + hdPathIndex.toString());
let wallet = node.getWallet();
const secretKey = wallet.getPrivateKeyString();
const address = wallet.getAddressString();
accumulatedAddrs.push({
secretKey,
address,
balance: ACCOUNTFUNDING,
});
const nextHDPathIndex = hdPathIndex + 1;
if (nextHDPathIndex === totalToGenerate) {
return accumulatedAddrs;
}
return generateAccounts(mnemonic, nextHDPathIndex, totalToGenerate, accumulatedAddrs);
}
function start() {
accounts = generateAccounts(mnemonic, 0, 100, [])
const testRPCInput = {
accounts,
locked: false
};
testrpc.server(testRPCInput).listen(8545);
}
function stop() {
}
module.exports = {
start,
stop,
account: function(index){
return accounts[index];
}
}