Skip to content

Commit 16f21b9

Browse files
committed
修复熊链领水地址格式错误
1 parent 699805d commit 16f21b9

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

.DS_Store

0 Bytes
Binary file not shown.

src/bearChain/bearToken.js

+31-24
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,34 @@ const config = require('../../config/runner.json');
55
const { HttpsProxyAgent } = require('https-proxy-agent');
66
const fakeUa = require('fake-useragent');
77
const userAgent = fakeUa();
8-
const { sleep, randomPause, sendRequest} = require('../../utils/utils.js');
8+
const { sleep, randomPause, sendRequest } = require('../../utils/utils.js');
99
const { createTask, getTaskResult } = require('../../utils/yesCaptcha/yesCaptcha.js');
10-
10+
const ethers = require('ethers');
1111

1212
const MAX_RETRIES = 5; // 最大重试次数
1313
const MAX_PROXY_CHECK_ATTEMPTS = 3;
1414

1515
const agent = new HttpsProxyAgent(config.proxy);
1616
const websiteKey = '0x4AAAAAAARdAuciFArKhVwt';
1717
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',
2020
'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',
2323
'content-type': 'text/plain;charset=UTF-8',
24-
'origin': 'https://artio.faucet.berachain.com/',
24+
'origin': 'https://artio.faucet.berachain.com/',
2525
'pragma': 'no-cache',
2626
'referer': 'https://artio.faucet.berachain.com/',
2727
'user-agent': userAgent,
2828
}
2929

3030
async function recaptcha() {
31-
const {taskId} = await createTask(websiteUrl, websiteKey, 'TurnstileTaskProxylessM1');
31+
const { taskId } = await createTask(websiteUrl, websiteKey, 'TurnstileTaskProxylessM1');
3232
let result = await getTaskResult(taskId);
3333
// 如果result为空,等待6秒后再次请求
3434
if (!result) {
35-
await sleep(0.1);
35+
await sleep(6);
3636
result = await getTaskResult(taskId);
3737
}
3838
// 如果再次为空,抛出错误
@@ -62,7 +62,7 @@ async function processAddresses(filePath) {
6262
});
6363
}
6464

65-
async function main(wallet) {
65+
async function main() {
6666
try {
6767
const addresses = await processAddresses(config.walletPath);
6868
console.log('开始领取测试币');
@@ -74,8 +74,8 @@ async function main(wallet) {
7474
console.log('测试代理IP是否正常');
7575
try {
7676
const response = await sendRequest('https://myip.ipip.net', {
77-
method: 'get',
78-
httpAgent: agent,
77+
method: 'get',
78+
httpAgent: agent,
7979
httpsAgent: agent
8080
});
8181
console.log('验证成功, IP信息: ', response);
@@ -93,16 +93,23 @@ async function main(wallet) {
9393
}
9494

9595
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}`);
97104

98105
let attempts = 0;
99106
while (attempts < MAX_RETRIES) {
100107
try {
101108

102109
const recaptchaToken = await recaptcha();
103110
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 };
106113
const urlConfig = {
107114
headers: headers,
108115
httpsAgent: agent,
@@ -114,15 +121,15 @@ async function main(wallet) {
114121
const response = await sendRequest(url, urlConfig);
115122
const txHash = response.msg;
116123
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} 次...`);
122129
await sleep(5);
123-
} else {
124-
console.error(`领取失败❌,地址:${address}:`, error);
125-
break; // 如果是非重试的错误,退出循环
130+
} else {
131+
console.error(`领取失败❌,地址:${checksumAddress}:`, error);
132+
break; // 如果是非重试的错误,退出循环
126133
}
127134
}
128135
}
@@ -132,4 +139,4 @@ async function main(wallet) {
132139
}
133140
}
134141

135-
main();
142+
main();

0 commit comments

Comments
 (0)