forked from jiang-24-gdufs/createRandomEVMWalletsCSV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (42 loc) · 1.17 KB
/
index.js
File metadata and controls
45 lines (42 loc) · 1.17 KB
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
const path = require('path');
const ethers = require('ethers');
const createObjectCsvWriter = require('csv-writer').createObjectCsvWriter;
const defaultOptions = {
number: 100,
path: './wallet.csv',
index: true,
privateKeyProps: 'privateKey',
addressProps: 'address'
}
const mergeOptions = (options) => {
return { ...defaultOptions, ...options }
}
function createEVMWalletCsv(options) {
if (Number.isFinite(options)) {
options = { number: options }
}
const { number, path, index, privateKeyProps, addressProps } = mergeOptions(options)
const data = Array(number).fill('_').map((_, i) => {
const wallet = ethers.Wallet.createRandom()
const { privateKey, address } = wallet
const result = {
privateKey: privateKey,
address: address
}
if (index) {
result.index = i
}
return result
})
const header = index ? [{ id: 'index', title: 'index' }] : []
const csvWriter = createObjectCsvWriter({
path: path,
header: [
...header,
{ id: 'address', title: privateKeyProps },
{ id: 'privateKey', title: addressProps },
],
});
return csvWriter.writeRecords(data)
}
module.exports = createEVMWalletCsv;