Skip to content

Instantly share code, notes, and snippets.

@JWPapi
Created October 3, 2022 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JWPapi/2703da427baac9c0b64bdb32e31eb2c2 to your computer and use it in GitHub Desktop.
Save JWPapi/2703da427baac9c0b64bdb32e31eb2c2 to your computer and use it in GitHub Desktop.
import axios from "axios"
import _ from "lodash"
import * as cheerio from "cheerio"
export default async function handler(req, res) {
const {address, start, end} = req.query
const tokenIds = _.range(start, end)
const urls = tokenIds.map((tokenId) => polygonScanUrlGenerator(address, tokenId))
const responses = await Promise.all(urls.map((url) => axios.get(url)))
const htmls = responses.map((response) => response.data)
const owners = htmls.map((html) => {
const $ = cheerio.load(html)
return $(`#resulttable .table tbody tr td:nth-child(2) a`).text()
})
const uniqueOwners = _.uniq(owners)
let failures = 0
const unMoonedWallets = await Promise.all(uniqueOwners.map(async (wallet, i) => {
await sleep(100, i)
const url = `https://nova-explorer.arbitrum.io/api?module=account&action=tokentx&address=${wallet}`
const response = await axios.get(url).catch((e) => {
failures++
console.log(e)
}
)
return response?.data.message === "No token transfers found" ? wallet : null
})).then((e) => e.filter(e => e))
res.json({uniqueOwners, unMoonedWallets})
}
const polygonScanUrlGenerator = (address, tokenId) => {
return `https://polygonscan.com/token/generic-tokenholder-inventory?m=normal&contractAddress=${address}&a=${tokenId}&pUrl=token`
}
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment