Skip to content

Instantly share code, notes, and snippets.

@CoolCatsNFTPublic
Last active July 27, 2021 09:35
Show Gist options
  • Save CoolCatsNFTPublic/c59ad54b6faf349dd38a3c15e2d14088 to your computer and use it in GitHub Desktop.
Save CoolCatsNFTPublic/c59ad54b6faf349dd38a3c15e2d14088 to your computer and use it in GitHub Desktop.
Get all Cool Cat holders
// THE GIST CONTAINS A DELIBERATE ERROR FOR THE PURPOSES
// OF THE ARTICLE - DO NOT BLINDLY COPY AND PASTE
async getAllHolders() {
// Step 1 - Get the total population
const totalSupply = await this.contract.methods.totalSupply().call();
// Step 2 - Iterate over live tokens and log owners
const holder = {};
for(let i = 0; i < totalSupply; i++){
const ownerAddress = await this.contract.methods.ownerOf(i).call();
if(!holder[ownerAddress]){
holder[ownerAddress] = 1;
} else {
holder[ownerAddress]++;
}
}
// Step 3 - Saving the snapshot
fs.writeFile('holders.json', JSON.stringify(holder),{ flag: 'w' },function (err) {
if (err) return console.log(err);
});
}
@CoolCatsNFTPublic
Copy link
Author

// THE GIST CONTAINS A DELIBERATE ERROR FOR THE PURPOSES
// OF THE ARTICLE - DO NOT BLINDLY COPY AND PASTE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment