Last active
July 27, 2021 09:35
-
-
Save CoolCatsNFTPublic/c59ad54b6faf349dd38a3c15e2d14088 to your computer and use it in GitHub Desktop.
Get all Cool Cat holders
This file contains hidden or 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
// 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); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// THE GIST CONTAINS A DELIBERATE ERROR FOR THE PURPOSES
// OF THE ARTICLE - DO NOT BLINDLY COPY AND PASTE