Skip to content

Commit

Permalink
增加avail领水脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsongsu committed Apr 9, 2024
1 parent 16f21b9 commit d2bd20f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 17 deletions.
Binary file modified .DS_Store
Binary file not shown.
96 changes: 96 additions & 0 deletions src/avail/getAvlToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const axios = require('axios');
const fs = require('fs');
const csv = require('csv-parser');
const config = require('../../config/runner.json');
const { HttpsProxyAgent } = require('https-proxy-agent');
const fakeUa = require('fake-useragent');
const userAgent = fakeUa();
const { sleep, randomPause, sendRequest } = require('../../utils/utils.js');
const { createTask, getTaskResult } = require('../../utils/yesCaptcha/yesCaptcha.js');

const MAX_RETRIES = 1; // 最大重试次数
const MAX_PROXY_CHECK_ATTEMPTS = 3;

const agent = new HttpsProxyAgent(config.proxy);
const websiteKey = '6Lc94akpAAAAAGaxYMKiA0qBqL10gSblHpeyD7xZ';
const websiteUrl = 'https://faucet.avail.tools/';

let headers = {
'accept': '*/*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.6',
'referer': 'https://faucet.avail.tools/',
'user-agent': userAgent,
}

async function recaptcha() {
const { taskId } = await createTask(websiteUrl, websiteKey, 'RecaptchaV3TaskProxylessM1');
let result = await getTaskResult(taskId);
// 如果result为空,等待6秒后再次请求
if (!result) {
await sleep(6);
result = await getTaskResult(taskId);
}
if (!result) {
throw new Error(`人机验证失败`);
}
const { gRecaptchaResponse } = result.solution;
return gRecaptchaResponse
}

async function processAddresses(filePath) {
const addresses = [];
return new Promise((resolve, reject) => {
fs.createReadStream(filePath)
.pipe(csv())
.on('data', (row) => {
addresses.push(row.polkaddress);
})
.on('end', () => {
console.log('地址读取完毕');
resolve(addresses);
})
.on('error', (error) => {
console.error('读取地址失败:', error);
reject(error);
});
});
}

async function main() {
try {
const polkAddresses = await processAddresses(config.walletPath);
console.log('开始领取测试币');

for (const polkAddress of polkAddresses) {
console.log(`领取地址: ${polkAddress}`);
const recaptchaToken = await recaptcha();
const response = await claimTestCoins(polkAddress, recaptchaToken);
console.log(`领取成功✅,地址:${polkAddress},结果:${response.success}`);

}
}
catch (error) {
console.error('领取测试币失败:', error);
}


}


async function claimTestCoins(polkAddress, recaptchaToken) {
const url = `https://faucet.avail.tools/api/faucet/claim?address=${polkAddress}&token=${recaptchaToken}`;
const data = {
address: polkAddress,
token: recaptchaToken,
};
const urlConfig = {
headers: headers,
httpsAgent: agent,
httpAgent: agent,
data: data,
};
return await axios.get(url, urlConfig);
}

main();
30 changes: 14 additions & 16 deletions src/lavaNet/getLavaRpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@ const agent = new HttpsProxyAgent(config.proxy);
const createCsvWriter = require('csv-writer').createObjectCsvWriter;

// 这里定义了邀请码,请自行更换成自己的邀请码
const inviteCode = 'YGM6I';
const inviteCode = 'SIRNB';
const provider = new Web3.providers.HttpProvider(config.ethrpc);
const web3 = new Web3(provider);

const headers = {
"accept": "application/json",
"accept-language": "zh-CN,zh;q=0.9",
"content-type": "application/json",
"sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"Referer": "https://points.lavanet.xyz/",
"Referrer-Policy": "strict-origin-when-cross-origin"
}
'authority': 'points-api.lavanet.xyz',
'accept': 'application/json',
'content-type': 'application/json',
'origin': 'https://points.lavanet.xyz',
'referer': 'https://points.lavanet.xyz/',
'sec-ch-ua-platform': '"Windows"',
'user-agent': userAgent,
'x-lang': 'english',
};


function getKeyFromUser() {
Expand All @@ -57,8 +54,9 @@ function decrypt(text, secretKey) {

async function login(wallet) {
const url = 'https://points-api.lavanet.xyz/accounts/metamask/login/';
const address = wallet.address.toLowerCase();
const data = {
account: wallet.address,
account: address,
invite_code: inviteCode,
process: 'token',
};
Expand Down Expand Up @@ -88,9 +86,9 @@ async function stringToHex (str) {
async function signLoginData(hexString, wallet) {
const url = 'https://points-api.lavanet.xyz/accounts/metamask/login/';
const signature = await web3.eth.accounts.sign(hexString, wallet.privateKey);

const address = wallet.address.toLowerCase();
const data = {
account: wallet.address,
account: address,
login_token: signature.signature,
invite_code: inviteCode,
process: 'verify',
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function randomPause() {
return Math.floor(Math.random() * (maxSeconds - minSeconds + 1)) + minSeconds;
}

async function sendRequest(url, urlConfig, timeout = 10000, maxRetries = 10) {
async function sendRequest(url, urlConfig, timeout = 10000, maxRetries = 3) {
let retries = 0;

while (retries < maxRetries) {
Expand Down

0 comments on commit d2bd20f

Please sign in to comment.