-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate_wallets.js
39 lines (30 loc) · 1.13 KB
/
generate_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
const { Keypair } = require('@solana/web3.js');
const bip39 = require('bip39');
const fs = require('fs');
async function generateWallets(count) {
const wallets = [];
for (let i = 0; i < count; i++) {
// Generate a 24-word mnemonic
const mnemonic = bip39.generateMnemonic(256);
// Derive a seed from the mnemonic
const seed = await bip39.mnemonicToSeed(mnemonic);
// Generate a Keypair from the seed
const keypair = Keypair.fromSeed(seed.slice(0, 32));
// Save wallet info
wallets.push({
address: keypair.publicKey.toBase58(),
privateKey: Buffer.from(keypair.secretKey).toString('hex'),
mnemonic
});
}
return wallets;
}
async function main() {
const walletCount = 50; // Number of wallets to generate
const wallets = await generateWallets(walletCount);
// Save wallets to a file
const outputFileName = 'solana_wallets.json';
fs.writeFileSync(outputFileName, JSON.stringify(wallets, null, 2));
console.log(`Generated ${walletCount} wallets and saved to ${outputFileName}`);
}
main().catch(console.error);