-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
98 lines (86 loc) · 3.04 KB
/
index.ts
File metadata and controls
98 lines (86 loc) · 3.04 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
import {createPublicClient, createWalletClient, http, parseUnits,formatEther, formatUnits, } from 'viem';
import {mainnet} from 'viem/chains';
import {privateKeyToAccount} from 'viem/accounts';
import pLimit from 'p-limit'
import fs from "fs";
// @ts-ignore
import Logger from "@youpaichris/logger";
const logger = new Logger();
// 线程数量
const concurrency = 1
const rpc_url = "https://eth-mainnet.public.blastapi.io"
const publicClient = createPublicClient({
chain: mainnet,
transport: http(rpc_url),
batch: {
multicall: {
batchSize: 1024,
wait: 16,
},
},
});
async function mintNft(accountInfo:string){
const logger = new Logger();
const [_, privateKey] = accountInfo.split('----')
const eoa_user = privateKeyToAccount(privateKey as `0x${string}`)
logger.setPrefix(`[${eoa_user.address}]`)
const walletClient = createWalletClient({
chain: mainnet,
transport: http(rpc_url),
account: eoa_user.address,
}
)
try{
const [eoaUserNonce, eoaUserBalance] = await Promise.all([
publicClient.getTransactionCount({ address: eoa_user.address }),
publicClient.getBalance({ address: eoa_user.address }),
]);
logger.info(`Nonce: ${eoaUserNonce} 余额: ${formatEther(eoaUserBalance)}`);
if(eoaUserBalance === 0n){
logger.warn(`余额为0`);
return { success: false, reason: '余额不足' };
}
const hash = await walletClient.sendTransaction({
account: eoa_user,
nonce: eoaUserNonce,
to: "0x26D85A13212433Fe6A8381969c2B0dB390a0B0ae",
data: '0x1249c58b',
})
logger.info(`交易发送成功: ${hash}`);
const receipt = await publicClient.waitForTransactionReceipt({
hash,
pollingInterval:1_000
});
logger.success(`交易已经确认,区块: ${receipt.blockNumber}`);
return { success: true, hash, receipt };
}catch(e){
logger.error(e);
return { success: false, reason: e };
}
}
async function main() {
logger.warn(`Version: 1.0.0`);
logger.warn(`Author: 0xNaixi`);
logger.warn(`验证码平台 https://www.nocaptcha.io/register?c=hLf08E`);
const newLimit = pLimit(concurrency)
const walletKeys = fs
.readFileSync("keys.txt", "utf8")
.split(/\r?\n/)
.filter((key) => key);
const promises = walletKeys.map(accountInfo => newLimit(() => mintNft(accountInfo)))
const results = await Promise.allSettled(promises)
let successCount = 0;
let failCount = 0;
results.forEach(result => {
if (result.status === 'fulfilled' && result.value?.success) {
successCount++;
} else {
failCount++;
}
});
logger.info(`\n=== 执行结果统计 ===`);
logger.success(`成功: ${successCount}个`);
logger.error(`失败: ${failCount}个`);
logger.info(`📊 总计: ${walletKeys.length}个`);
}
main().catch(console.error);