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 transfer ( wallet , nonce ) {
30
+ const contactAddress = wallet . address . toLowerCase ( ) . replace ( '0x' , '' ) ;
31
+ const transactionData = `0xe3414c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000005f5e0ff0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001200000000000000000000000004fc1cefa83eef32ec2f00d3d487306a0fc9f0a4d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000007eeca4205ff31f947edbd49195a7a88e6a91161b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b3e70dfddf31591b05ec61b2e3b2e84176956460000000000000000000000007eeca4205ff31f947edbd49195a7a88e6a91161b0000000000000000000000000000000000000000000000010bb64c217024088b0000000000000000000000006581e59a1c8da66ed0d313a0d4029dce2f746cc5000000000000000000000000000000000000000000000000000218c8b49fbca600000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000`
32
+ try {
33
+ const gasPrice = await wallet . provider . getGasPrice ( ) ;
34
+ const txToEstimate = {
35
+ to : "0x0d5862FDbdd12490f9b4De54c236cff63B038074" ,
36
+ data : transactionData ,
37
+ } ;
38
+ const gasLimit = await wallet . estimateGas ( txToEstimate ) ;
39
+
40
+ const txData = {
41
+ to : "0x0d5862FDbdd12490f9b4De54c236cff63B038074" ,
42
+ data : transactionData ,
43
+ gasPrice : gasPrice ,
44
+ gasLimit : gasLimit ,
45
+ nonce : nonce ,
46
+ value : 10000000000000 ,
47
+ } ;
48
+
49
+ const tx = await wallet . sendTransaction ( txData ) ;
50
+ console . log ( 'transfer stusd:' , tx . hash ) ;
51
+
52
+ } catch ( error ) {
53
+ console . error ( '发送交易时出错:' , error ) ;
54
+ }
55
+ }
56
+
57
+ async function main ( ) {
58
+ const secretKey = getKeyFromUser ( ) ;
59
+ const wallets = [ ] ;
60
+
61
+ fs . createReadStream ( config . walletPath )
62
+ . pipe ( csv ( ) )
63
+ . on ( 'data' , ( row ) => {
64
+ const decryptedPrivateKey = decrypt ( row . privateKey , secretKey ) ;
65
+ wallets . push ( { ...row , decryptedPrivateKey } ) ;
66
+ } )
67
+ . on ( 'end' , async ( ) => {
68
+ for ( const walletInfo of wallets ) {
69
+ const provider = new ethers . providers . JsonRpcProvider ( "https://rpc.ankr.com/berachain_testnet" ) ;
70
+ const wallet = new ethers . Wallet ( walletInfo . decryptedPrivateKey , provider ) ;
71
+ const nonce = await wallet . getTransactionCount ( ) ;
72
+ await transfer ( wallet , nonce ) ;
73
+ }
74
+ } ) ;
75
+
76
+ }
77
+
78
+ main ( ) ;
0 commit comments