@@ -5,34 +5,34 @@ const config = require('../../config/runner.json');
5
5
const { HttpsProxyAgent } = require ( 'https-proxy-agent' ) ;
6
6
const fakeUa = require ( 'fake-useragent' ) ;
7
7
const userAgent = fakeUa ( ) ;
8
- const { sleep, randomPause, sendRequest} = require ( '../../utils/utils.js' ) ;
8
+ const { sleep, randomPause, sendRequest } = require ( '../../utils/utils.js' ) ;
9
9
const { createTask, getTaskResult } = require ( '../../utils/yesCaptcha/yesCaptcha.js' ) ;
10
-
10
+ const ethers = require ( 'ethers' ) ;
11
11
12
12
const MAX_RETRIES = 5 ; // 最大重试次数
13
13
const MAX_PROXY_CHECK_ATTEMPTS = 3 ;
14
14
15
15
const agent = new HttpsProxyAgent ( config . proxy ) ;
16
16
const websiteKey = '0x4AAAAAAARdAuciFArKhVwt' ;
17
17
const websiteUrl = 'https://artio.faucet.berachain.com/' ;
18
- headers = {
19
- 'authority' : 'artio-80085-faucet-api-cf.berachain.com' ,
18
+ let headers = {
19
+ 'authority' : 'artio-80085-faucet-api-cf.berachain.com' ,
20
20
'accept' : '*/*' ,
21
- 'accept-language' : 'zh-CN,zh;q=0.9' ,
22
- 'cache-control' : 'no-cache' ,
21
+ 'accept-language' : 'zh-CN,zh;q=0.9' ,
22
+ 'cache-control' : 'no-cache' ,
23
23
'content-type' : 'text/plain;charset=UTF-8' ,
24
- 'origin' : 'https://artio.faucet.berachain.com/' ,
24
+ 'origin' : 'https://artio.faucet.berachain.com/' ,
25
25
'pragma' : 'no-cache' ,
26
26
'referer' : 'https://artio.faucet.berachain.com/' ,
27
27
'user-agent' : userAgent ,
28
28
}
29
29
30
30
async function recaptcha ( ) {
31
- const { taskId} = await createTask ( websiteUrl , websiteKey , 'TurnstileTaskProxylessM1' ) ;
31
+ const { taskId } = await createTask ( websiteUrl , websiteKey , 'TurnstileTaskProxylessM1' ) ;
32
32
let result = await getTaskResult ( taskId ) ;
33
33
// 如果result为空,等待6秒后再次请求
34
34
if ( ! result ) {
35
- await sleep ( 0.1 ) ;
35
+ await sleep ( 6 ) ;
36
36
result = await getTaskResult ( taskId ) ;
37
37
}
38
38
// 如果再次为空,抛出错误
@@ -62,7 +62,7 @@ async function processAddresses(filePath) {
62
62
} ) ;
63
63
}
64
64
65
- async function main ( wallet ) {
65
+ async function main ( ) {
66
66
try {
67
67
const addresses = await processAddresses ( config . walletPath ) ;
68
68
console . log ( '开始领取测试币' ) ;
@@ -74,8 +74,8 @@ async function main(wallet) {
74
74
console . log ( '测试代理IP是否正常' ) ;
75
75
try {
76
76
const response = await sendRequest ( 'https://myip.ipip.net' , {
77
- method : 'get' ,
78
- httpAgent : agent ,
77
+ method : 'get' ,
78
+ httpAgent : agent ,
79
79
httpsAgent : agent
80
80
} ) ;
81
81
console . log ( '验证成功, IP信息: ' , response ) ;
@@ -93,16 +93,23 @@ async function main(wallet) {
93
93
}
94
94
95
95
for ( const address of addresses ) {
96
- console . log ( `领取地址: ${ address } ` ) ;
96
+ let checksumAddress ;
97
+ try {
98
+ checksumAddress = ethers . utils . getAddress ( address ) ;
99
+ } catch ( error ) {
100
+ console . error ( `地址格式错误: ${ address } ` , error ) ;
101
+ continue ; // 跳过无效地址
102
+ }
103
+ console . log ( `领取地址: ${ checksumAddress } ` ) ;
97
104
98
105
let attempts = 0 ;
99
106
while ( attempts < MAX_RETRIES ) {
100
107
try {
101
108
102
109
const recaptchaToken = await recaptcha ( ) ;
103
110
headers [ 'authorization' ] = `Bearer ${ recaptchaToken } ` ;
104
- const url = `https://artio-80085-faucet-api-cf.berachain.com/api/claim?address=${ address } ` ;
105
- const data = { address : address } ;
111
+ const url = `https://artio-80085-faucet-api-cf.berachain.com/api/claim?address=${ checksumAddress } ` ;
112
+ const data = { address : checksumAddress } ;
106
113
const urlConfig = {
107
114
headers : headers ,
108
115
httpsAgent : agent ,
@@ -114,15 +121,15 @@ async function main(wallet) {
114
121
const response = await sendRequest ( url , urlConfig ) ;
115
122
const txHash = response . msg ;
116
123
console . log ( '领取成功✅ ' , txHash ) ;
117
- attempts = MAX_RETRIES ;
118
- } catch ( error ) {
119
- if ( error . response && error . response . data . message === 'Faucet is overloading, please try again' ) {
120
- attempts ++ ;
121
- console . log ( `地址${ address } 正在重试第 ${ attempts } 次...` ) ;
124
+ break ; // 成功后退出循环
125
+ } catch ( error ) {
126
+ attempts ++ ;
127
+ if ( error . response && error . response . data && error . response . data . message === 'Faucet is overloading, please try again' ) {
128
+ console . log ( `地址${ checksumAddress } 正在重试第 ${ attempts } 次...` ) ;
122
129
await sleep ( 5 ) ;
123
- } else {
124
- console . error ( `领取失败❌,地址:${ address } :` , error ) ;
125
- break ; // 如果是非重试的错误,退出循环
130
+ } else {
131
+ console . error ( `领取失败❌,地址:${ checksumAddress } :` , error ) ;
132
+ break ; // 如果是非重试的错误,退出循环
126
133
}
127
134
}
128
135
}
@@ -132,4 +139,4 @@ async function main(wallet) {
132
139
}
133
140
}
134
141
135
- main ( ) ;
142
+ main ( ) ;
0 commit comments