Skip to content

Instantly share code, notes, and snippets.

@fxfactorial
Created July 4, 2021 00:58
Show Gist options
  • Save fxfactorial/54d26a5e5c53c3de4f1412e78bbf44bf to your computer and use it in GitHub Desktop.
Save fxfactorial/54d26a5e5c53c3de4f1412e78bbf44bf to your computer and use it in GitHub Desktop.
suck faucets
const puppeteer = require('puppeteer');
const spawn = require('@expo/spawn-async');
const v4 = require('uuid').v4;
const UserAgent = require('user-agents');
const faucet = 'https://explorer.certik.foundation/faucet';
const address_query = 'input[name=address]';
const button_click = 'form button[type=submit]';
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
const pull_token = async (port, browser) => {
const new_addr = v4();
try {
const {
output: [stdout, stderr],
} = await spawn('python3', ['create-key.py', new_addr]);
const cleaned_up = stdout.trim();
const page = await browser.newPage();
const userAgent = new UserAgent();
await page.setUserAgent(userAgent.toString());
await page.goto(faucet, { waitUntil: 'load', timeout: 0 });
await page.type(address_query, cleaned_up);
await sleep(2500);
await page.click(button_click);
await sleep(25 * 1000);
await spawn('python3', ['send-and-delegate.py', new_addr]);
await sleep(30* 1000);
} catch (e) {
console.log('some issue- whatever', e);
} finally {
await spawn('python3', ['remove-junk.py', new_addr]);
}
};
(async function main() {
const ports = [
'12050',
// '12052', '12053', '12054',
];
let iter = 0;
const port = ports[0];
const chromeOptions = {
headless: true,
defaultViewport: null,
args: [`--proxy-server=socks5://127.0.0.1:${port}`],
};
let browser = await puppeteer.launch(chromeOptions);
while (true) {
const {
output: [stdout],
} = await spawn('certikcli', ['status', '--output', 'json']);
const status = JSON.parse(stdout.trim());
if (status.sync_info.catching_up === true) {
console.log('no point to try and make accounts, not synced up, need to catchup');
await sleep(20 * 60 * 1000);
continue;
}
for (const port of ports) {
try {
await pull_token(port, browser);
console.log(`successful loop ${iter}`);
await sleep(10 * 1000);
iter++;
if (iter % 10 === 0) {
console.log({iter, msg: '10th count, restarting brower instance'})
browser.close();
browser = await puppeteer.launch(chromeOptions);
}
} catch(e) {
console.log(`some issue on round ${iter}`, e);
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment