-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
120 lines (98 loc) · 3.02 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const fs = require('fs');
const axios = require('axios');
const base64 = require('base-64');
const solanaWeb3 = require('@solana/web3.js');
const { decode } = require('bs58');
const bs58 = require('bs58');
const client = axios.create({
timeout: 30000,
headers: {
Origin: 'https://jup.ag',
},
});
const rpcClient = new solanaWeb3.Connection(
'https://jupiter-fe.helius-rpc.com/',
'confirmed'
);
const args = process.argv.slice(2);
const numWallets = args.length > 0 ? parseInt(args[0], 10) : 50;
if (isNaN(numWallets) || numWallets <= 0) {
console.error('Please provide a valid number of wallets to create.');
process.exit(1);
}
const walletKeys = [];
const successKeys = [];
async function main() {
// 1、批量创建钱包
for (let i = 0; i < numWallets; i++) {
const userKey = solanaWeb3.Keypair.generate();
// const address = userKey.publicKey.toString();
const privateKey = bs58.encode(userKey.secretKey);
walletKeys.push(privateKey);
}
fs.writeFileSync('wallet.txt', walletKeys.join('\n'), 'utf-8');
const walletContent = fs.readFileSync('wallet.txt', 'utf8');
const lines = walletContent.split('\n').filter((line) => line.trim() !== '');
const wallets = lines.map((line) => {
const secretKey = bs58.decode(line.trim());
return solanaWeb3.Keypair.fromSecretKey(secretKey);
});
if (wallets.length === 0) {
console.error('No wallets found in wallet.txt');
process.exit(1);
}
wallets.forEach((wallet) => {
processWallet(wallet);
});
}
async function processWallet(wallet) {
while (true) {
const txRaw = await getTx(wallet.publicKey.toBase58());
if (!txRaw) {
continue;
}
await sendTx(wallet, txRaw);
}
}
async function getTx(address) {
try {
const response = await client.post(
'https://proxy.dial.to/?url=https%3A%2F%2Fsolanasummer.click%2Fon%2Fmint',
{ account: address }
);
return response.data.transaction || '';
} catch (error) {
console.error('Error fetching transaction:', address);
return '';
}
}
async function sendTx(wallet, rawtx) {
try {
const txData = base64.decode(rawtx);
const tx = solanaWeb3.Transaction.from(Buffer.from(txData, 'base64'));
tx.partialSign(wallet);
const signature = await solanaWeb3.sendAndConfirmTransaction(
rpcClient,
tx,
[wallet],
{ commitment: 'confirmed' }
);
const privateKey = bs58.encode(wallet.secretKey);
// 从wallet.txt中删除 mint 成功的私钥
const index = walletKeys.indexOf(privateKey);
if (index > -1) {
walletKeys.splice(index, 1);
fs.writeFileSync('wallet.txt', walletKeys.join('\n'), 'utf-8');
}
// 添加到成功列表
successKeys.push(privateKey);
fs.writeFileSync('success.txt', successKeys.join('\n'), 'utf-8');
console.log('Mint success:', {
address: wallet.publicKey.toBase58(),
tx: signature,
});
} catch (error) {
console.error('Error sending transaction:', error);
}
}
main().catch((err) => console.error('Error in main function:', err));