Last active
September 21, 2020 20:29
-
-
Save miguelmota/12717785f77e3dd4b5582dcde24e367c to your computer and use it in GitHub Desktop.
UNI token claim checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const fetch = require('node-fetch') | |
const BN = require('bignumber.js') | |
async function makeRequest (address) { | |
const url = `https://gentle-frost-9e74.uniswap.workers.dev/1/${address}` | |
const res = await fetch(url) | |
const json = await res.json() | |
return json | |
} | |
async function main () { | |
const data = fs.readFileSync('addresses.csv', 'utf8') | |
const lines = data.split('\n') | |
const startIndex = process.argv[2] >>> 0 | |
for (let i = startIndex; i < lines.length; i++) { | |
const address = lines[i] | |
if (!address) { | |
console.error(`${i} empty line`) | |
continue | |
} | |
try { | |
const result = await makeRequest(address) | |
const amountHex = result.amount | |
if (!amountHex) { | |
console.error(`${i} ${address} ${result.message}`) | |
continue | |
} | |
const amount = new BN(amountHex).div(new BN(10e17)).toNumber() | |
console.log(`${i} ${address} ${amount}`) | |
} catch (err) { | |
console.error(`${i} ${address} ${err.message}`) | |
} | |
} | |
} | |
main() | |
// Usage: | |
// $ touch addresses.csv | |
// $ node index.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment