Skip to content

Instantly share code, notes, and snippets.

@stevyhacker
Created June 16, 2022 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save stevyhacker/c75e0ccfc49b3f146d1c373e14c75eff to your computer and use it in GitHub Desktop.
Save stevyhacker/c75e0ccfc49b3f146d1c373e14c75eff to your computer and use it in GitHub Desktop.
NFT holders snapshot tool
import fetch from 'node-fetch';
import fs from 'fs';
var requestOptions = {
method: 'GET',
redirect: 'follow'
};
const apiKey = "INSERT_YOUR_OWN_API_KEY_HERE"
const collections = [
{name: 'BAYC', address: '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d'},
{name: 'MAYC', address: '0x60e4d786628fea6478f785a6d7e704777c86a7c6'},
{name: 'Decentraland', address: '0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d'},
{name: 'Sandbox', address: '0x5CC5B05a8A13E3fBDB0BB9FcCd98D38e50F90c38'},
{name: 'LobsterDAO', address: '0x026224A2940bFE258D0dbE947919B62fE321F042'}
]
const baseURL = `https://eth-mainnet.alchemyapi.io/nft/v2/${apiKey}/getOwnersForCollection`;
collections.forEach(nft => {
const fetchURL = `${baseURL}?contractAddress=${nft.address}`;
fetch(fetchURL, requestOptions)
.then(response => response.json())
// .then(response => JSON.stringify(response, null, 2))
.then(response => {
const holders = response.ownerAddresses.map((e) => {
return e;
});
fs.writeFile("./" + nft.name + "_snapshot.csv", holders.join("\r\n"), (err) => {
console.log(err || "Snapshot for " + nft.name + " saved.");
});
})
.catch(error => console.log('error', error));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment