|
@@ -0,0 +1,35 @@
|
|
|
+import axios from 'axios'
|
|
|
+import dotenv from 'dotenv'
|
|
|
+import polly from 'polly-js'
|
|
|
+dotenv.config()
|
|
|
+
|
|
|
+const googlekey = '6LdLhtYpAAAAAOe1xmceNR-i6MTtzq7N6AYztoVI'
|
|
|
+const captchaApiKey = process.env.CAPTCHA_API_KEY
|
|
|
+
|
|
|
+export async function getCaptcha(address: string) {
|
|
|
+ return await polly()
|
|
|
+ .waitAndRetry(2)
|
|
|
+ .executeForPromise(async () => {
|
|
|
+ const res = await axios.post('https://2captcha.com/in.php', {
|
|
|
+ method: 'userrecaptcha',
|
|
|
+ key: captchaApiKey,
|
|
|
+ googlekey,
|
|
|
+ pageUrl: `https://faucet.testnet.initia.xyz/?address=${address}`,
|
|
|
+ json: 1,
|
|
|
+ action: 'verify',
|
|
|
+ })
|
|
|
+ const request = res.data.request
|
|
|
+ return await polly()
|
|
|
+ .waitAndRetry([10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000])
|
|
|
+ .executeForPromise(async () => {
|
|
|
+ const captchaRes = await axios.get(
|
|
|
+ `https://2captcha.com/res.php?key=${captchaApiKey}&action=get&id=${request}&json=1`,
|
|
|
+ )
|
|
|
+ const token = captchaRes.data.request
|
|
|
+ console.log(token)
|
|
|
+ if (token === 'CAPCHA_NOT_READY') throw new Error('CAPCHA_NOT_READY')
|
|
|
+ if (!token) throw new Error('no result')
|
|
|
+ return token
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|