How to Get a List of NFT Holders for a Given Collection (2024)

📘

API Endpoint

This tutorial uses the getOwnersForContract endpoint.

Getting a list of wallet addresses that hold an NFT from a particular collection is an incredibly insightful piece of data. You could track the behavior of these wallets, and gain useful insights about the market. You could also generate analytics that mapped interests to wallets.

Although a vast number of companies and projects harvest NFT ownership data to display to their users, doing so through traditional means is not an easy task. Typically, you would have to spin up a node, and call the ownerOf function of the ERC-721 or ERC-1155 contract. Since it is not uncommon for NFT collections to have 10,000+ NFTs, it also means that you'll have to call the aforementioned function many, many times.

This process can be expensive and time consuming. Fortunately, we can save on time and engineering efforts by replacing all the above work with a single call to getOwnersForContract.

About this Tutorial

We will write a simple script in Node to gets us all the owners of the World of Women collection using a free Alchemy developer account and the NFT API.

Step 1: Install Node and npm

In case you haven't already, install node and npm on your local machine.

Make sure that node is at least v14 or higher by typing the following in your terminal:

node -v

Step 2: Create an Alchemy app

In case you haven't already, sign up for a free Alchemy account.

How to Get a List of NFT Holders for a Given Collection (1)

Next, navigate to the Alchemy Dashboard and create a new app.

Make sure you set the chain to Ethereum and network to Mainnet.

Once the app is created, click on your app's View Key button on the dashboard.

Take a note of the API KEY and HTTPS URL.

The URL will be in this form: https://eth-mainnet.g.alchemy.com/v2/xxxxxxxxx

You will need this later.

Step 3: Create a node project

Let's now create an empty repository and install all node dependencies.

To make requests to the NFT API, use the Alchemy SDK.

You can also use axios or fetch alternatively.

mkdir nft-holders && cd nft-holdersnpm init -ynpm install --save alchemy-sdktouch main.js
mkdir nft-holders && cd nft-holdersnpm init -ynpm install --save axiostouch main.js
mkdir nft-holders && cd nft-holdersnpm init -ytouch main.js

This will create a repository named nft-holders that holds all your files and dependencies.

Next, open this repo in your favorite code editor.

We will be writing all our code in the main.js file.

Step 4: Get all current holders of the NFT collection

To get all holders of a particular NFT collection, we will use the getOwnersForCollection method.

This method takes in one required argument:

  1. contractAddress: The address of the NFT collection (an ERC-721 or an ERC-1155 contract)

Note that it is also possible to optionally set a block height parameter. We do not need to do this here since it is set to the latest block by default.

Add the following code to the main.js file.

const { Alchemy, Network } = require("alchemy-sdk");const config = { apiKey: "<-- ALCHEMY API KEY -->", network: Network.ETH_MAINNET,};const alchemy = new Alchemy(config);const main = async () => { // WOW contract address const address = "0xe785E82358879F061BC3dcAC6f0444462D4b5330"; // Get owners const owners = await alchemy.nft.getOwnersForContract(address); console.log(owners);};const runMain = async () => { try { await main(); process.exit(0); } catch (error) { console.log(error); process.exit(1); }};runMain();
const axios = require('axios')// WOW contract addressconst address = "0xe785E82358879F061BC3dcAC6f0444462D4b5330";// Alchemy URLconst baseURL = `<-- ALCHEMY HTTP URL -->`;const url = `${baseURL}/getOwnersForCollection/?contractAddress=${address}`;const config = { method: 'get', url: url,};// Make the request and print the formatted response:axios(config) .then(console.log) .catch(error => console.log('error', error));
import fetch from 'node-fetch';// WOW contract addressconst address = "0xe785E82358879F061BC3dcAC6f0444462D4b5330";const baseURL = "<-- ALCHEMY APP HTTP URL -->";const url = `${baseURL}/getOwnersForCollection/?contractAddress=${address}`;var requestOptions = { method: 'get', redirect: 'follow'};fetch(url, requestOptions) .then(response => console.log) .catch(error => console.log('error', error))

Run the following command on your terminal:

node main.js

If all goes well, you should see output that looks something like this:

{ owners: [ '0x00189b281d7249950ecbe735653536c4a1821351', '0x0026691eed3d9ca5dcf7351dfbe113e6dfce528d', ........ '0x050dd8aa03290cd4552882804239629912423f56', '0x05158928d3b7764187c691da53cef446aeb32f31', '0x05171c1ed768ccd3fe3b609f499b5405e4542682', '0x0522197898a464c83966eec76e441e391224e178', ... 5465 more items ]}

Conclusion

Congratulations! You now know how to use the Alchemy NFT API to get a list of all holders of an NFT collection or contract.

If you enjoyed this tutorial on how to get all holders of an NFT collection, give us a tweet @AlchemyPlatform.

Don't forget to join our Discord server to meet other blockchain devs, builders, and entrepreneurs.

Ready to start using the Alchemy NFT API?

Create a free Alchemy account and share your project with us!

Updated almost 2 years ago

How to Get a List of NFT Holders for a Given Collection (2024)
Top Articles
Security Clearance Questions
Background Investigation Process
Exclusive: Baby Alien Fan Bus Leaked - Get the Inside Scoop! - Nick Lachey
Dollywood's Smoky Mountain Christmas - Pigeon Forge, TN
Gabriel Kuhn Y Daniel Perry Video
Mcoc Immunity Chart July 2022
Flights to Miami (MIA)
Achivr Visb Verizon
Meg 2: The Trench Showtimes Near Phoenix Theatres Laurel Park
Wmlink/Sspr
Slay The Spire Red Mask
Aries Auhsd
OnTrigger Enter, Exit ...
Https://Gw.mybeacon.its.state.nc.us/App
Hope Swinimer Net Worth
อพาร์ทเมนต์ 2 ห้องนอนในเกาะโคเปนเฮเกน
Regal Stone Pokemon Gaia
Walmart Windshield Wiper Blades
Studentvue Columbia Heights
Teenleaks Discord
Overton Funeral Home Waterloo Iowa
U Break It Near Me
Geometry Review Quiz 5 Answer Key
Sunset Time November 5 2022
The best brunch spots in Berlin
Dashboard Unt
UCLA Study Abroad | International Education Office
Danielle Ranslow Obituary
Giantbodybuilder.com
Login.castlebranch.com
Gt7 Roadster Shop Rampage Engine Swap
Sam's Club Gas Price Hilliard
How does paysafecard work? The only guide you need
What Are Digital Kitchens & How Can They Work for Foodservice
Whitehall Preparatory And Fitness Academy Calendar
Studio 22 Nashville Review
Rage Of Harrogath Bugged
Weather Underground Bonita Springs
Pay Entergy Bill
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Nina Flowers
Rs3 Nature Spirit Quick Guide
56X40X25Cm
Matt Brickman Wikipedia
Frequently Asked Questions
Ephesians 4 Niv
Sc Pick 3 Past 30 Days Midday
Marcel Boom X
Sams La Habra Gas Price
Craigslist Cars And Trucks For Sale By Owner Indianapolis
Bones And All Showtimes Near Emagine Canton
Coldestuknow
Latest Posts
Article information

Author: Delena Feil

Last Updated:

Views: 6076

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.