-
Notifications
You must be signed in to change notification settings - Fork 32
/
createAccounts.js
47 lines (39 loc) · 1.41 KB
/
createAccounts.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";
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(makeCosmoshubPath(i));
}
let wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, ops);
resolve(wallet);
})
}
const readline = createInterface({
input: process.stdin,
output: process.stdout
});
readline.question("How many wallets do you want to create:\n", async(input) => {
let numOfWallets = Number(input);
for (let i = 0; i < numOfWallets; i++) {
let mnemonic = await walletGenerate();
console.log(`MNEMONIC${i}: `+mnemonic);
let wallet = await getWalletWithAccountSize(mnemonic,1,'cosmos');
let accounts = await wallet.getAccounts();
for(let account of accounts){
console.log(`ADDRESS${i}: ${account.address}`);
}
console.log("====================================")
}
process.exit()
});