1
+ const config = require ( "../../config/runner.json" ) ;
2
+ const csv = require ( "csv-parser" ) ;
3
+ const ethers = require ( "ethers" ) ;
4
+ const crypto = require ( 'crypto' ) ;
5
+ const fs = require ( 'fs' ) ;
6
+
7
+ function getKeyFromUser ( ) {
8
+ let key ;
9
+ if ( process . env . SCRIPT_PASSWORD ) {
10
+ key = process . env . SCRIPT_PASSWORD ;
11
+ } else {
12
+ key = readlineSync . question ( '请输入你的密码: ' , {
13
+ hideEchoBack : true ,
14
+ } ) ;
15
+ }
16
+ return crypto . createHash ( 'sha256' ) . update ( String ( key ) ) . digest ( 'base64' ) . substr ( 0 , 32 ) ;
17
+ }
18
+
19
+ function decrypt ( text , secretKey ) {
20
+ let parts = text . split ( ':' ) ;
21
+ let iv = Buffer . from ( parts . shift ( ) , 'hex' ) ;
22
+ let encryptedText = Buffer . from ( parts . join ( ':' ) , 'hex' ) ;
23
+ let decipher = crypto . createDecipheriv ( 'aes-256-cbc' , Buffer . from ( secretKey ) , iv ) ;
24
+ let decrypted = decipher . update ( encryptedText ) ;
25
+ decrypted = Buffer . concat ( [ decrypted , decipher . final ( ) ] ) ;
26
+ return decrypted . toString ( ) ;
27
+ }
28
+
29
+ async function claimKey ( wallet , nonce ) {
30
+ const transactionData = `0x2c29f64e` ;
31
+
32
+ try {
33
+ const gasPrice = await wallet . provider . getGasPrice ( ) ;
34
+ const txToEstimate = {
35
+ to : "0x0f3284bFEbc5f55B849c8CF792D39cC0f729e0BC" ,
36
+ data : transactionData ,
37
+ } ;
38
+ const gasLimit = await wallet . estimateGas ( txToEstimate ) ;
39
+
40
+ const txData = {
41
+ to : "0x0f3284bFEbc5f55B849c8CF792D39cC0f729e0BC" ,
42
+ data : transactionData ,
43
+ gasPrice : gasPrice ,
44
+ gasLimit : gasLimit ,
45
+ nonce : nonce ,
46
+ value : 0 ,
47
+ } ;
48
+
49
+ const tx = await wallet . sendTransaction ( txData ) ;
50
+ console . log ( 'claim key:' , tx . hash ) ;
51
+
52
+ } catch ( error ) {
53
+ console . error ( '发送交易时出错:' , error ) ;
54
+ }
55
+ }
56
+
57
+ function sleep ( ms ) {
58
+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
59
+ }
60
+
61
+ async function randomSleep ( ) {
62
+ const min = 10000 ; // 10 seconds in milliseconds
63
+ const max = 30000 ; // 30 seconds in milliseconds
64
+ const randomTime = Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
65
+
66
+ console . log ( `Sleeping for ${ randomTime / 1000 } seconds...` ) ;
67
+ await sleep ( randomTime ) ;
68
+ console . log ( "Awake!" ) ;
69
+ }
70
+
71
+ async function main ( ) {
72
+ const secretKey = getKeyFromUser ( ) ;
73
+ const wallets = [ ] ;
74
+
75
+ fs . createReadStream ( config . walletPath )
76
+ . pipe ( csv ( ) )
77
+ . on ( 'data' , ( row ) => {
78
+ const decryptedPrivateKey = decrypt ( row . privateKey , secretKey ) ;
79
+ wallets . push ( { ...row , decryptedPrivateKey } ) ;
80
+ } )
81
+ . on ( 'end' , async ( ) => {
82
+ for ( const walletInfo of wallets ) {
83
+ const provider = new ethers . providers . JsonRpcProvider ( "https://rpc.ankr.com/polygon" ) ;
84
+ const wallet = new ethers . Wallet ( walletInfo . decryptedPrivateKey , provider ) ;
85
+ const nonce = await wallet . getTransactionCount ( ) ;
86
+ await randomSleep ( ) ;
87
+ claimKey ( wallet , nonce ) ;
88
+ }
89
+ } ) ;
90
+
91
+ }
92
+
93
+ main ( ) ;
0 commit comments