forked from nirholas/pump-fun-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-usage.ts
More file actions
60 lines (45 loc) · 1.89 KB
/
basic-usage.ts
File metadata and controls
60 lines (45 loc) · 1.89 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @fileoverview Basic usage example for the Solana vanity address generator.
*
* This example demonstrates the simplest way to generate a vanity address
* using the TypeScript library.
*
* Run with: npx ts-node examples/basic-usage.ts
*/
import { VanityGenerator, saveKeypair } from '../src/lib';
async function main(): Promise<void> {
console.log('🔑 Solana Vanity Address Generator - Basic Example\n');
// Configure the prefix you want
const prefix = 'So';
console.log(`Searching for address starting with "${prefix}"...\n`);
// Create the generator
const generator = new VanityGenerator({
prefix,
// Optional: report progress every 1000 attempts
onProgress: (attempts, rate) => {
process.stdout.write(`\rAttempts: ${attempts.toLocaleString()} | Rate: ${rate.toFixed(0)}/sec`);
},
});
// Show difficulty estimate
const estimated = generator.getEstimatedAttempts();
console.log(`Expected attempts: ~${estimated.toLocaleString()}`);
console.log(`Estimated time: ${generator.getTimeEstimate(15000)}\n`);
// Generate the address
const result = await generator.generate();
// Clear the progress line
process.stdout.write('\r' + ' '.repeat(60) + '\r');
console.log('\n✅ Found matching address!\n');
console.log(` Address: ${result.publicKey}`);
console.log(` Attempts: ${result.attempts.toLocaleString()}`);
console.log(` Duration: ${(result.duration / 1000).toFixed(2)}s\n`);
// Save to file
const outputPath = `${result.publicKey}.json`;
await saveKeypair(result.secretKey, outputPath);
console.log(`📁 Keypair saved to: ${outputPath}\n`);
console.log('⚠️ IMPORTANT: Keep this file secure!');
console.log(' It contains your private key.\n');
console.log('Usage examples:');
console.log(` solana config set --keypair ${outputPath}`);
console.log(` solana balance ${result.publicKey}`);
}
main().catch(console.error);