-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlazy-wallet.ts
35 lines (33 loc) · 993 Bytes
/
lazy-wallet.ts
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
import fs from 'fs';
import { ethers } from 'ethers';
(async () => {
const wallet = ethers.Wallet.createRandom();
const dataTable = [];
for (let i = 0; i < 5; i += 1) {
const newWallet = wallet.deriveChild(i);
dataTable.push({
path: newWallet.path,
address: await newWallet.getAddress(),
});
}
for (let i = 100; i < 105; i += 1) {
const newWallet = wallet.deriveChild(i);
dataTable.push({
path: newWallet.path,
address: await newWallet.getAddress(),
});
}
const walletList = dataTable.map(({ path, address }) => {
return `# ${path}\t${address}`;
});
const fileContent = fs.existsSync('.env') ? fs.readFileSync('.env', 'utf-8') : '';
if (fileContent.indexOf('OROCHI_MNEMONIC') === -1) {
fs.writeFileSync(
'.env',
`${fileContent}\n${walletList.join('\n')}\nOROCHI_MNEMONIC="${wallet.mnemonic?.phrase.trim()}"`,
);
console.table(dataTable);
} else {
console.log('Wallets existed');
}
})();