-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-n-wallets.js
50 lines (38 loc) · 1.52 KB
/
create-n-wallets.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
49
50
const BCHN_MAINNET = "https://bchn.fullstack.cash/v5/";
const BCHJS = require("@psf/bch-js");
const fs = require('fs')
let bchjs;
bchjs = new BCHJS({ restURL: BCHN_MAINNET });
const lang = "english"; // Set the language of the wallet.
//this array is how many wallets you want to print
let numOfPubKeys = ["1","2","3","4","5"];
const getPubkeyBuffArray = async () => {
const results = await
Promise.all(numOfPubKeys.map(e => e = createPubKeys(e)))
return results
}
getPubkeyBuffArray()
async function createPubKeys(nameOfWallets) {
try {
let words = bchjs.Mnemonic.generate(128, bchjs.Mnemonic.wordLists()[lang]);
arr = [words].join();
// create root seed
let toSeed = await bchjs.Mnemonic.toSeed(arr);
// master HDNode
let masterHdnode = bchjs.HDNode.fromSeed(toSeed);
// Use 245 derivation path, which is the BIP44 standard for SLP tokens.
let listChildNodes = masterHdnode.derivePath("m/44'/245'/0'/0/0");
const wallet = {
mnemonic: words,
cashAddress: bchjs.HDNode.toCashAddress(listChildNodes),
slpAddress: bchjs.SLP.HDNode.toSLPAddress(listChildNodes),
legacyAddress: bchjs.HDNode.toLegacyAddress(listChildNodes),
WIF: bchjs.HDNode.toWIF(listChildNodes)
};
//console.log(wallet);
fs.writeFileSync(wallet${wallet,nameOfWallets}.json, JSON.stringify(wallet, null, 2))
//console.log(wallet${wallet,nameOfWallets}.json, JSON.stringify(wallet, null, 2))
} catch (err) {
console.error("Error in createWallets(): ", err);
}
}