-
Notifications
You must be signed in to change notification settings - Fork 4
/
captcha.js
71 lines (62 loc) · 2.18 KB
/
captcha.js
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
const capthaAPIKey = "YOUR_KEY_HERE";
async function getCaptchaId() {
const apiEndpoint = "https://2captcha.com/in.php";
const params = new URLSearchParams({
key: capthaAPIKey,
method: "hcaptcha",
sitekey: "73ec4927-b43f-40b1-b61a-646a5ec58a45",
pageurl: "https://app.seinetwork.io/faucet/",
});
const response = await fetch(`${apiEndpoint}?${params}`);
const responseBody = await response.text();
if (responseBody.startsWith("OK|")) {
return responseBody.substr(3); // Return captcha ID without the "OK|" prefix
} else {
throw new Error(`Failed to get captcha ID: ${responseBody}`);
}
}
async function sendSeiRequest(captchaKey, address) {
const url = "https://faucet-v2.seinetwork.io/atlantic-2";
const data = {
address: address,
captchaKey: captchaKey
}
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
});
const result = await response.json();
console.log(`Address: ${address} status: ${result.status}`);
} catch (err) {
console.log(`Error occurred in captcha function: ${err}`)
}
}
async function getCaptchaResult(captchaId) {
const url = `https://2captcha.com/res.php?key=${capthaAPIKey}&action=get&id=${captchaId}`;
try{
let response = await fetch(url);
let result = await response.text();
while (result.includes('CAPCHA_NOT_READY')) {
// Повторяем запрос через 5 секунд
await new Promise(resolve => setTimeout(resolve, 5000));
response = await fetch(url);
result = await response.text();
}
return result;
} catch (err) {
console.log(`Error occurred in captcha function: ${err}`)
}
}
export const getFunds = async (address) => {
try {
const captchaId = await getCaptchaId();
const captchaResult = await getCaptchaResult(captchaId);
await sendSeiRequest(captchaResult.substr(3), address);
} catch (err) {
console.log(err)
}
}