From d2bd20f350513d62395e7d2d8b932488ab4b3a5a Mon Sep 17 00:00:00 2001 From: songsu Date: Tue, 9 Apr 2024 23:36:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0avail=E9=A2=86=E6=B0=B4?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 8196 -> 8196 bytes src/avail/getAvlToken.js | 96 ++++++++++++++++++++++++++++++++++++++ src/lavaNet/getLavaRpc.js | 30 ++++++------ utils/utils.js | 2 +- 4 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 src/avail/getAvlToken.js diff --git a/.DS_Store b/.DS_Store index bc442b85930e97f8842f8aa453175388df887487..e9cce554f7f05ffc50c8ae1636cb056e17e427c8 100644 GIT binary patch delta 25 gcmZp1XmQx!BFtfKW}>5DWN9|}f`I+zZsAHE0Aq^>t^fc4 delta 25 gcmZp1XmQx!BFtfGWT2y9WN9|}f`I+zZsAHE0AlS2qyPW_ diff --git a/src/avail/getAvlToken.js b/src/avail/getAvlToken.js new file mode 100644 index 0000000..08e423f --- /dev/null +++ b/src/avail/getAvlToken.js @@ -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(); \ No newline at end of file diff --git a/src/lavaNet/getLavaRpc.js b/src/lavaNet/getLavaRpc.js index f383a30..9bb4cfa 100644 --- a/src/lavaNet/getLavaRpc.js +++ b/src/lavaNet/getLavaRpc.js @@ -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() { @@ -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', }; @@ -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', diff --git a/utils/utils.js b/utils/utils.js index edaae7e..83fafc9 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -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) {