Skip to content

Instantly share code, notes, and snippets.

@M4cs
Created August 19, 2023 16:42
Show Gist options
  • Save M4cs/b1a92809fa44d48c6714ce400a75ac39 to your computer and use it in GitHub Desktop.
Save M4cs/b1a92809fa44d48c6714ce400a75ac39 to your computer and use it in GitHub Desktop.
Ethscriptions Snapshot Tool
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