-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
203 lines (187 loc) · 6.12 KB
/
index.js
File metadata and controls
203 lines (187 loc) · 6.12 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
const fs = require('fs/promises');
const axios = require('axios');
const { HttpsProxyAgent } = require('https-proxy-agent');
const API_KEY = 'Solve_Captcha_API_KEY';
const SITE_KEY = 'da2c2c8e-4150-444a-8cfc-2b12635c8846';
const SITE_URL = 'https://faucet.haust.app';
const FAUCET_API_URL = 'https://faucet.haust.app/api/claim';
const REQUEST_TIMEOUT = 30000;
const MAX_RETRIES = 3;
const THREAD_COUNT = 3;
const PROXY_FILE = 'proxy.txt';
const ADDRESS_FILE = 'address.txt';
async function loadProxies(filename = PROXY_FILE) {
try {
const data = await fs.readFile(filename, 'utf8');
return data
.split('\n')
.map((line) => line.trim())
.filter((line) => line);
} catch (err) {
console.error(`Error reading proxies file: ${err.message}`);
return [];
}
}
async function readAddresses(filename = ADDRESS_FILE) {
try {
const data = await fs.readFile(filename, 'utf8');
return data
.split('\n')
.map((line) => line.trim())
.filter((line) => line);
} catch (err) {
console.error(`Error reading addresses file: ${err.message}`);
return [];
}
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function solveHCaptchaWithRetry(retries = MAX_RETRIES) {
for (let attempt = 1; attempt <= retries; attempt++) {
try {
const submitUrl = 'https://api.solvecaptcha.com/in.php';
const payload = new URLSearchParams({
key: API_KEY,
method: 'hcaptcha',
sitekey: SITE_KEY,
pageurl: SITE_URL,
json: '1',
});
const submitRes = await axios.post(submitUrl, payload.toString(), {
timeout: REQUEST_TIMEOUT,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
if (!submitRes.data || submitRes.data.status !== 1) {
throw new Error(
`API Error (submit captcha): ${submitRes.data?.request || 'Unknown error'}`
);
}
const captchaId = submitRes.data.request;
console.log(`Captcha task submitted. ID: ${captchaId}`);
const retrieveUrl = 'https://api.solvecaptcha.com/res.php';
const startTime = Date.now();
while (Date.now() - startTime < 2 * 60 * 1000) {
await sleep(0);
const pollParams = new URLSearchParams({
key: API_KEY,
action: 'get',
id: captchaId,
json: '1',
});
const pollRes = await axios.get(`${retrieveUrl}?${pollParams.toString()}`, {
timeout: REQUEST_TIMEOUT,
});
if (!pollRes.data) {
console.log(`Invalid JSON response: ${pollRes}`);
continue;
}
if (pollRes.data.status === 1) {
return {
token: pollRes.data.request,
user_agent: pollRes.data.useragent || '',
};
} else if (
String(pollRes.data.request || '').includes('CAPCHA_NOT_READY')
) {
continue;
} else {
throw new Error(
`API Error (polling captcha): ${pollRes.data.request || 'Unknown error'}`
);
}
}
throw new Error('Timeout waiting for captcha solution');
} catch (err) {
if (attempt < retries) {
console.log(`Attempt ${attempt} failed, retrying... Error: ${err.message}`);
await sleep(100 * attempt);
} else {
throw new Error(`Captcha solving failed after ${retries} attempts: ${err.message}`);
}
}
}
}
async function claimFaucetWithRetry(address, captchaData, proxy, retries = MAX_RETRIES) {
const payload = { address };
const headers = {
accept: '*/*',
'content-type': 'application/json',
'h-captcha-response': captchaData.token,
'User-Agent': captchaData.user_agent || '',
};
for (let attempt = 1; attempt <= retries; attempt++) {
try {
let agent = undefined;
if (proxy) {
agent = new HttpsProxyAgent(proxy);
}
const response = await axios.post(FAUCET_API_URL, payload, {
headers,
timeout: REQUEST_TIMEOUT,
httpAgent: agent,
httpsAgent: agent,
});
return response.data;
} catch (err) {
console.log(`Attempt ${attempt} failed, retrying faucet claim... Error: ${err.message}`);
if (attempt < retries) {
await sleep(5000 * attempt);
} else {
throw new Error(`Faucet claim failed after ${retries} attempts: ${err.message}`);
}
}
}
}
async function processAddress(address, getNextProxy) {
console.log(`\nProcessing address: ${address}`);
try {
console.log('Solving hCaptcha...');
const captchaData = await solveHCaptchaWithRetry();
console.log(`Successfully solved hCaptcha. Token: ${captchaData.token.slice(0, 30)}...`);
const proxy = getNextProxy();
console.log(`Claiming faucet using proxy: ${proxy ? proxy.slice(0, 20) + '...' : 'None'}`);
const result = await claimFaucetWithRetry(address, captchaData, proxy);
console.log('Claim result:', JSON.stringify(result, null, 2));
} catch (err) {
console.error(`Error processing address ${address}: ${err.message}`);
}
}
async function main() {
const addresses = await readAddresses();
const proxies = await loadProxies();
if (addresses.length === 0) {
console.log('No addresses found in address.txt');
return;
}
if (proxies.length === 0) {
console.log('Warning: No proxies found in proxy.txt - will make direct faucet claims.');
proxies.push(null);
}
let proxyIndex = 0;
function getNextProxy() {
const proxy = proxies[proxyIndex % proxies.length];
proxyIndex += 1;
return proxy;
}
const totalAddresses = addresses.length;
let currentIndex = 0;
async function worker() {
while (currentIndex < totalAddresses) {
const addrIndex = currentIndex++;
const address = addresses[addrIndex];
await processAddress(address, getNextProxy);
await sleep(1);
}
}
const workers = [];
for (let i = 0; i < THREAD_COUNT; i++) {
workers.push(worker());
}
await Promise.all(workers);
}
main().catch((err) => {
console.error(`Unhandled error in main: ${err.message}`);
});