Created
August 19, 2023 16:42
-
-
Save M4cs/b1a92809fa44d48c6714ce400a75ac39 to your computer and use it in GitHub Desktop.
Ethscriptions Snapshot Tool
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 axios = require('axios'); | |
const fs = require('fs'); | |
const BASE_URL = 'https://api.ethscriptions.com/api/ethscriptions/filtered'; | |
const COLLECTION = 'mfpurrs'; // Collection Name | |
const sleep = ms => new Promise(r => setTimeout(r, ms)); | |
async function main() { | |
let total_count = 0; | |
try { | |
const response = await axios.get(BASE_URL, { | |
params: { | |
collection: COLLECTION, | |
page: 0 | |
} | |
}); | |
total_count = response.data.total_count; | |
} catch (error) { | |
console.error(`Failed to fetch initial page.`); | |
return null; | |
} | |
const total_pages = Math.ceil(total_count / 25); | |
console.log(`Fetching snapshot for ${COLLECTION}`); | |
let owners = []; | |
for (let i = 0; i <= total_pages; i++) { | |
const res = await axios.get(BASE_URL, { | |
params: { | |
collection: COLLECTION, | |
page: i | |
} | |
}); | |
const ethscriptions = res.data.ethscriptions; | |
const _owners = ethscriptions.map(item => item.current_owner); | |
owners.push(..._owners); | |
await sleep(200); | |
console.log(`Fetched Page: ${i}`); | |
} | |
// Filtering out duplicate owners | |
const uniqueOwners = Array.from(new Set(owners)); | |
console.log(`Total unique Owners: ${uniqueOwners.length}`); | |
fs.writeFileSync(`./${COLLECTION}-snapshot.json`, JSON.stringify(uniqueOwners, null, 4)); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment