-
Notifications
You must be signed in to change notification settings - Fork 32
/
createMultipleSecretAccounts.js
47 lines (37 loc) · 1.37 KB
/
createMultipleSecretAccounts.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
import { Secp256k1HdWallet, makeCosmoshubPath } from "@cosmjs/amino";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { createInterface } from "readline";
import { stringToPath } from "@cosmjs/crypto";
async function walletGenerate() {
let wallet = await Secp256k1HdWallet.generate(24);
return wallet.secret.data;
}
function getWalletWithAccountSize(mnemonic, accountSize, prefix) {
return new Promise(async (resolve) => {
let ops = {
bip39Password: "",
hdPaths: [],
prefix: prefix,
}
for (let i = 0; i < accountSize; i++) {
ops.hdPaths.push(stringToPath(`m/44'/529'/0'/0/${i}`));
}
let wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, ops);
resolve(wallet);
})
}
const readline = createInterface({
input: process.stdin,
output: process.stdout
});
readline.question("How many Secret Network accounts do you want to create:\n", async (input) => {
let numOfAccounts = Number(input);
let mnemonic = await walletGenerate();
console.log(`MNEMONIC: ` + mnemonic);
let wallet = await getWalletWithAccountSize(mnemonic, numOfAccounts, 'secret');
let accounts = await wallet.getAccounts();
for (let i=0;i<accounts.length;i++) {
console.log(`ADDRESS${i}: ${accounts[i].address}`);
}
process.exit()
});