How to Get the Minters of an NFT Collection
Learn how to get the \day 1\ minters of an NFT collection. The addresses that originally minted an NFT collection (first owners).
Don’t have an API key?
Sign up or upgrade your plan for access. Get started for free
This tutorial uses the getAssetTransfers and getOwnersForContract endpoints.
Introduction
If you are an owner of an NFT collection, you might want to reward the first minters of your NFT for supporting your project from day 1. In this tutorial, we will show you how to find the original minters of an NFT collection, as well as check which minters are still holding that NFT. To accomplish this, we will be using the getAssetTransfers and verifyNftOwnership endpoints. Let’s get started!
“Original Minters” or “Day 1 Minters” refers to the wallet addresses that minted the NFT from the NFT contract.
If someone bought the NFT from a secondary marketplace like Opensea, they are not considered to be an original minter or day 1 minter.
Setting up the project
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:
Create an Alchemy app
In case you haven’t already, sign up for a free Alchemy account.
Alchemy’s account dashboard where developers can create a new app on the Ethereum blockchain.
Next, navigate to the Alchemy Dashboard and create a new app.
Make sure you set the chain to Ethereum and the network to Mainnet. Once the app is created, click on your app’s View Key button on the dashboard.
Take note of the HTTP URL.
The URL will be in this form: https://eth-mainnet.g.alchemy.com/v2/xxxxxxxxx
You will need this later.
Create a node project
Let’s now create an empty repository and install all node dependencies.
Run the following commands in order to create your node project and install Alchemy SDK.
This will create a repository named nft-minter-getter
that holds all your files and dependencies.
Next, open this repo in your favorite code editor.
Now our project is set up and we are ready to write code. We will write all our code in the main.js
file.
Writing the script
For the sake of this tutorial, we will be finding the minters of the Bored Ape Yacht Club NFT. To get the minter addresses, we will use the getAssetTransfers method.
- We can pass a
fromAddress
and acontractAddress
to this method specifying that thecontractAddress
is the address of an ERC721 token. It will then return all the transfers of NFTs for thatcontractAddress
with the specifiedfromAddress
. - Then we can specify the
fromAddress
to be0x0000000000000000000000000000000000000000
(null address) to get the mint transactions because during a mint the token is transferred from the null address to the minter’s address. We will then filter out theto
addresses from these transactions, which will be the addresses of the minters of the NFT collection.
Add the following code to the main.js
file:
If you face a failed response
error, try swapping the demo
key with your personal Alchemy API key.
Here’s an explanation of what the code is doing:
- We first import the Alchemy SDK to be able to use it.
- Then we configure the Alchemy SDK with the API key and the correct network.
- We then define a variable that stores the contract address of the NFT whose minters we want to find.
- We also set another variable called
minters
as an empty array to store the minters of the NFT Collection - Furthermore, we define a function called
getMinters
that contains the logic to get the minters of the NFT collection. - Inside the
getMinters
function we make a call to thegetAssetTransfers
method to get all the transfers for the specifiedcontractAddress
in which thefromAddress
is0x0000000000000000000000000000000000000000
(null address). These transfers will essentially be the mints because when an NFT is minted, it is transferred from the null address to the minter. - The API call returns an object with a
transfers
key, which is an array of all the transfer objects with the conditions we specified. - Each transfer object has a property called
to
which is the address to which the NFT was transferred (minter address). - Then we loop through the response of the API call (array of transfer objects) pushing the
to
address to theminters
array. - We keep repeating this process until the
pageKey
exists. So this allows us to go through all the transfers. - We remove all the duplicate addresses from the
minters
array. This is done because the API call returns the sameto
address multiple times if an address minted multiple NFTs. - Finally, we log the number of unique minters and the
minters
array.
Run the script using:
You should see an output like this:
So from here, we can see that there were 981 “day 1” minters of the BAYC NFT!
This is how you can get the minters of an NFT collection.
Checking if the minters still hold the NFT
To check if the minters still hold an NFT from the collection we can use the getOwnersForContract endpoint to get an array of the current owners of the NFT collection. We can then loop through the minters
array and for each minter
if that minter
is in the currentOwners
array then that minter is still the holder of the collection.
So, the complete script will look like this:
Here’s an explanation of the new checkIfHolder
function that we added:
- The function defines a variable called
holdingDay1Minters
to store the number of minters who are still holders of the NFT collection. - Then it continues by making an API call to the getOwnersForContract method to get the current owners of the NFT collection.
- It then loops through the original minters of the collection (stored in the
minters
array) and checks if each minter is still a current owner of the collection. If a minter is still a current owner, theholdingDay1Minters
variable is incremented by 1. - At the end, we log the number and percentage of day 1 minters who still hold the NFT.
Please note that here we are checking if the minters still hold an NFT from the NFT Collection. That NFT can be any NFT that is part of the collection, not necessarily the NFT (token id) that the minter originally minted.
If you want to check that the minters still hold exactly the same NFT (token id) that they minted originally, you can use the getOwnersForToken endpoint.
Run the script using:
You should see an output like this:
From here we can observe that only 90 “day 1” minters of BAYC are still holding the NFT. That’s about 9.17% of the initial minters!
Conclusion
Congratulations! You now know how to use the getAssetTransfers and getOwnersForContract APIs to get the “day 1” minters of an NFT collection and check if they still hold the NFT!
If you enjoyed this tutorial, give us a tweet @Alchemy.
Don’t forget to join our Discord server to meet other blockchain devs, builders, and entrepreneurs.