Last active
September 3, 2022 06:42
-
-
Save zhongfu/c494be2dd29549b747ca3b0740004aa6 to your computer and use it in GitHub Desktop.
dumps a csv of owners of an nft collection (with sequential ids), and how many nfts they own
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
#!/usr/bin/env python3.8 | |
import brownie | |
from brownie import Contract | |
import csv | |
def main(): | |
brownie.network.connect('mainnet') | |
# lobsterdao, or plop your contract addr here | |
nft_contract = Contract('0x026224a2940bfe258d0dbe947919b62fe321f042') | |
total_supply = nft_contract.totalSupply() | |
# hopefully faster with multicall | |
with brownie.multicall: | |
owners = [nft_contract.ownerOf(i) for i in range(0, total_supply)] | |
# count num occurrences of each address, then sort in reverse order | |
owner_addresses = set(owners) | |
count_per_address = {addr: owners.count(addr) for addr in owner_addresses} | |
count_per_address = dict(sorted(count_per_address.items(), key=lambda x: x[1], reverse=True)) | |
with open('nft_owners.csv', 'w') as f: | |
writer = csv.writer(f) | |
writer.writerow(['address', 'count']) | |
writer.writerows(count_per_address.items()) | |
print('\n'.join([f"{addr}: {count}" for addr, count in count_per_address.items()])) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment