-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmint.js
More file actions
360 lines (327 loc) · 12.1 KB
/
Copy pathmint.js
File metadata and controls
360 lines (327 loc) · 12.1 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
const fs = require('fs');
const path = require('path');
const { SuiClient } = require('@mysten/sui.js/client');
const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
const { TransactionBlock } = require('@mysten/sui.js/transactions');
const { fromHEX } = require('@mysten/sui.js/utils');
const { HttpsProxyAgent } = require('https-proxy-agent');
const axios = require('axios');
const chalk = require('chalk');
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
const ora = require('ora');
const Table = require('cli-table3');
const nacl = require('tweetnacl');
const pLimit = require('p-limit');
const { bech32 } = require('bech32');
const { displayBanner } = require('./banner');
const CONFIG = {
threads: 20, // Config threads
maxRetries: 5,
rpcUrl: 'https://sui-rpc.publicnode.com',
privateKeyFile: 'priv.txt',
proxyFile: 'proxies.txt',
successFile: 'success.txt',
failFile: 'fail.txt',
packageId: '0x352919f09a96e8bca46cd2a9015c5651aed4aa3ca270f8c09c96ef670c8ede59',
moduleName: 'sui_passport',
functionName: 'mint_passport',
sharedObjectId: '0xf7bea21283a25287debc250a426a03f68cf9abbf03752094e9072e637058572b'
};
function getTimestamp() {
const now = new Date();
return `[${now.toLocaleTimeString()} ${now.toLocaleDateString()}]`;
}
function getKeypairFromPrivateKey(privateKey) {
try {
privateKey = privateKey.trim();
let seedBuffer;
if (privateKey.startsWith('suiprivkey')) {
const decoded = bech32.decode(privateKey, 1000);
const words = decoded.words;
seedBuffer = Buffer.from(bech32.fromWords(words));
if (seedBuffer.length === 33) {
seedBuffer = seedBuffer.slice(1);
}
} else {
const cleaned = privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey;
seedBuffer = Buffer.from(cleaned, 'hex');
}
if (seedBuffer.length !== 32) {
throw new Error(`Expected seed length 32, got ${seedBuffer.length}`);
}
const seed = new Uint8Array(seedBuffer);
const naclKeyPair = nacl.sign.keyPair.fromSeed(seed);
return Ed25519Keypair.fromSecretKey(naclKeyPair.secretKey.slice(0, 32));
} catch (error) {
throw new Error(`Failed to create keypair: ${error.message}`);
}
}
async function getCurrentIP(axiosInstance) {
try {
const response = await axiosInstance.get('https://api.ipify.org?format=json');
return response.data.ip;
} catch (error) {
return `Unknown (Error: ${error.message})`;
}
}
function createAxiosInstance(proxy = null) {
const config = {};
if (proxy) {
config.httpsAgent = new HttpsProxyAgent(proxy);
config.proxy = false;
}
return axios.create(config);
}
function createSuiClient(proxy = null) {
const clientConfig = { url: CONFIG.rpcUrl };
if (proxy) {
clientConfig.agent = new HttpsProxyAgent(proxy);
}
return new SuiClient(clientConfig);
}
async function mintNFT(suiClient, keypair) {
try {
const tx = new TransactionBlock();
const sharedObjectId = CONFIG.sharedObjectId;
const walletAddress = keypair.getPublicKey().toSuiAddress();
const last5 = walletAddress.slice(-5);
tx.moveCall({
target: `${CONFIG.packageId}::${CONFIG.moduleName}::${CONFIG.functionName}`,
arguments: [
tx.object(sharedObjectId),
tx.pure(last5),
tx.pure(""),
tx.pure(""),
tx.pure(""),
tx.pure(""),
tx.pure(""),
tx.object("0x4a4317676aa05a8e673dad0b2cc2fbf855b7170b5259340e2b76121bccbe9363"),
tx.object("0x0000000000000000000000000000000000000000000000000000000000000006")
]
});
const result = await suiClient.signAndExecuteTransactionBlock({
signer: keypair,
transactionBlock: tx,
options: { showEffects: true, showEvents: true }
});
return result;
} catch (error) {
throw new Error(`Failed to create or send transaction: ${error.message}`);
}
}
function readFileLines(filePath) {
try {
const content = fs.readFileSync(filePath, 'utf8');
return content.split('\n').filter(line => line.trim().length > 0);
} catch (error) {
throw new Error(`Failed to read file ${filePath}: ${error.message}`);
}
}
function saveResult(walletAddress, privateKey, success = true) {
const filePath = success ? CONFIG.successFile : CONFIG.failFile;
const data = `${walletAddress}:${privateKey}\n`;
try {
fs.appendFileSync(filePath, data);
} catch (error) {
console.error(`Failed to write file ${filePath}: ${error.message}`);
}
}
async function processWallet(workerData) {
const { index, privateKey, proxies, proxyIndex } = workerData;
let keypair, walletAddress;
try {
keypair = getKeypairFromPrivateKey(privateKey);
walletAddress = keypair.getPublicKey().toSuiAddress();
} catch (error) {
parentPort.postMessage({
type: 'log',
data: { index, message: `Failed to create keypair: ${error.message}`, color: 'red' }
});
return { success: false, error: error.message };
}
let currentProxyIndex = proxyIndex;
let currentProxy = proxies && proxies.length > 0 ? proxies[currentProxyIndex] : null;
function useNextProxy() {
currentProxyIndex = (currentProxyIndex + 1) % proxies.length;
currentProxy = proxies[currentProxyIndex];
}
function buildClients() {
const axiosInstance = createAxiosInstance(currentProxy);
return { axiosInstance, suiClient: createSuiClient(currentProxy) };
}
let { axiosInstance, suiClient } = buildClients();
{
const ip = await getCurrentIP(axiosInstance);
parentPort.postMessage({
type: 'log',
data: { index, message: `Starting with IP: ${ip}`, color: 'cyan' }
});
}
let attempt = 1;
while (attempt <= CONFIG.maxRetries) {
parentPort.postMessage({
type: 'log',
data: { index, message: `Attempt ${attempt}/${CONFIG.maxRetries} to mint NFT`, color: 'yellow' }
});
try {
const result = await mintNFT(suiClient, keypair);
if (result && result.digest) {
parentPort.postMessage({
type: 'log',
data: { index, message: `Mint NFT succeeded, digest: ${result.digest}`, color: 'green' }
});
parentPort.postMessage({
type: 'save',
data: { walletAddress, privateKey, success: true }
});
return { success: true };
} else {
const errorMsg = result.effects?.status?.error || 'Unknown error';
parentPort.postMessage({
type: 'log',
data: { index, message: `Mint failed: ${errorMsg}`, color: 'red' }
});
if (proxies && proxies.length > 0) {
useNextProxy();
({ axiosInstance, suiClient } = buildClients());
}
attempt++;
}
} catch (error) {
if (error.message.includes('429')) {
parentPort.postMessage({
type: 'log',
data: { index, message: `Received 429 error. Rotating proxy and retrying (not counting attempt).`, color: 'red' }
});
if (proxies && proxies.length > 0) {
useNextProxy();
({ axiosInstance, suiClient } = buildClients());
}
await new Promise(res => setTimeout(res, 2000));
} else {
parentPort.postMessage({
type: 'log',
data: { index, message: `Error: ${error.message}`, color: 'red' }
});
if (proxies && proxies.length > 0) {
useNextProxy();
({ axiosInstance, suiClient } = buildClients());
}
attempt++;
}
}
}
parentPort.postMessage({
type: 'log',
data: { index, message: `All attempts failed for wallet ${walletAddress}`, color: 'red' }
});
parentPort.postMessage({
type: 'save',
data: { walletAddress, privateKey, success: false }
});
return { success: false };
}
if (!isMainThread) {
(async () => {
try {
const result = await processWallet(workerData);
parentPort.postMessage({ type: 'done', data: result });
} catch (error) {
parentPort.postMessage({ type: 'error', data: error.message });
}
})();
}
async function main() {
displayBanner();
if (!isMainThread) return;
console.log(chalk.cyan(`Threads: ${CONFIG.threads}`));
console.log(chalk.cyan(`Max retries: ${CONFIG.maxRetries}`));
let privateKeys = [];
let proxies = [];
try {
privateKeys = readFileLines(CONFIG.privateKeyFile);
console.log(chalk.cyan(`Loaded ${privateKeys.length} wallets from ${CONFIG.privateKeyFile}`));
} catch (error) {
console.error(chalk.red(error.message));
process.exit(1);
}
try {
proxies = readFileLines(CONFIG.proxyFile);
console.log(chalk.cyan(`Loaded ${proxies.length} proxies from ${CONFIG.proxyFile}`));
} catch (error) {
console.log(chalk.yellow(`Proxy file not found or unreadable. Running without proxy.`));
}
if (privateKeys.length === 0) {
console.error(chalk.red(`No private keys found in ${CONFIG.privateKeyFile}`));
process.exit(1);
}
for (const filePath of [CONFIG.successFile, CONFIG.failFile]) {
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, '');
}
}
const tasks = privateKeys.map((privateKey, i) => ({
index: i + 1,
privateKey,
proxies,
proxyIndex: proxies.length > 0 ? i % proxies.length : 0
}));
const limit = pLimit(CONFIG.threads);
const results = await Promise.all(tasks.map(task => limit(() => {
return new Promise((resolve, reject) => {
const worker = new Worker(__filename, { workerData: task });
worker.on('message', (message) => {
const { type, data } = message;
if (type === 'log') {
const timestamp = getTimestamp();
console.log(`${timestamp} ${chalk[data.color](`[Wallet ${data.index}] ${data.message}`)}`);
} else if (type === 'save') {
saveResult(data.walletAddress, data.privateKey, data.success);
} else if (type === 'done') {
resolve(data);
} else if (type === 'error') {
resolve({ success: false, error: data });
}
});
worker.on('error', (error) => {
resolve({ success: false, error: error.message });
});
worker.on('exit', (code) => {
if (code !== 0) {
console.error(`Worker exited with code ${code}`);
}
});
});
})));
let successful = 0, failed = 0;
results.forEach(r => {
if (r.success) {
successful++;
} else {
failed++;
}
});
console.log(chalk.cyan('\n=== Summary ==='));
const Table = require('cli-table3');
const table = new Table({
head: [
chalk.cyan('Total Wallets'),
chalk.green('Success'),
chalk.red('Fail'),
chalk.yellow('Output Files')
]
});
table.push([
tasks.length,
successful,
failed,
`${CONFIG.successFile}, ${CONFIG.failFile}`
]);
console.log(table.toString());
}
if (isMainThread) {
main().catch(error => {
console.error(chalk.red(`Error: ${error.message}`));
process.exit(1);
});
}