How To Retrieve Owners of an NFT Collection on Ethereum

Idowu Daniel
Crossmint Tech
Published in
5 min readAug 2, 2022

Retrieving the owners of your NFTs without the proper tools can be a cumbersome task for dApp developers. Retrieving the owners of your NFTs could come in handy if you intend to airdrop tokens to holders of your NFT, or when issuing a community pass for exclusive NFT projects.

In this article, we will walk you through the process of retrieving the owners of your Ethereum NFTs.

What are NFTs?

The term “NFT” refers to a non-fungible token, a non-exchangeable representation of information or data kept on a blockchain. They can be traded or sold in a manner similar to digital playing cards. NFTs can contain various data formats, including photos, graphics, video, audio, gifs, and even tweets.

NFTs also ensure the reliability of digital files and are based on a decentralized blockchain.

How To Retrieve the Owners of Ethereum NFTs

Ownership is a very important aspect of NFTs. From a conventional perspective, it has been a cumbersome task for developers to query such data. However, established infrastructures like Alchemy and Moralis help developers save time and increase sync time when building web3 apps. In this article, we will walk you through how you can retrieve the owners of your NFT using Alchemy’s API.

The API we will be using is getOwnersForCollection which essentially gets all owners for a given contract. It is supported on Ethereum and Polygon networks and only requires one parameter, which is the contract address of the contract, and returns an array containing the list of addresses that own that NFT. NFTs can have a single owner (ERC-721) or multiple owners (ERC-1155).

Before retrieving a list of NFT owners, you may want to create and mint your own collection! You can follow our step-by-step guide here to do so:

Otherwise, you’ll want to find the contract address of the collection you’re searching for! You can search for Ethereum collections on OpenSea.

Prerequisites

You will need the following for this tutorial:

  • NodeJs is installed (version 16)
  • NPM package installed (version 8)
  • Alchemy Developer account

You have to sign in to your Alchemy developer account, you can create one here. Next, you will create an app and add details as shown below:

Take note of the API key; we will be using it later in this tutorial.

Next, we need to create a new node.js environment to make our NFT API request. Alchemy provides us with Alchemy SDK, Axios, and fetch libraries so that with a few lines of code, we can query owners of ERC-1155 NFTs.

We will use the NFT (NityPins#1 from NiftyPins ERC-1155 Collection V2), an NFT collection based on the Ethereum blockchain with the ERC-1155 token standard and has multiple owners.

First, we need to create a new directory:

mkdir retrieve-owners && cd retrieve-owners

Next, we’ll go ahead to initialize the project:

npm init -y

The npm init command converts your folder into an npm-based Javascript project. We then need to install the Alchemy SDK. Alchemy’s SDK makes it easier for developers to use Alchemy’s APIs and endpoints allowing access to the Alchemy NFT API.

npm install — save @alch/alchemy-sdk

Next, we will create an empty file using touch. Touch is used in node.js and will create an empty file if it doesn’t exist.

touch main.js

The getOwnersForToken function to retrieve the owners of an Ethereum NFT accepts two arguments:

  • contractAddress: The NFT’s smart contract address (ERC-721 or ERC-1155)
  • tokenId
For our project, the contract address is “0x67BcbC1C0E120D0A700Eb38A2d769C20A1DfB8f6” and the tokenId is “3”

Next, we will copy the following into the main.js file and replace with our API key where required:

Next, run this script by running the following command in your terminal:

node main.js

It should give an output like this:

Congratulations, we have now retrieved the owners of NityPins#1 from NiftyPins ERC-1155 Collection V2.

What’s next?

Once you’ve retrieved the owners of an Ethereum NFT collection, you may want to send them NFTs or tokens as a reward. Follow our guide to learn how to airdrop NFTs on Ethereum here:

What is Crossmint?

Our goal at Crossmint is to help make NFTs as accessible as possible. Our first product, Crossmint Pay, is a tool for NFT creators to accept credit card payments. It allows anyone to create an NFT in under a minute using only their email and credit card, with no need for a wallet or cryptocurrency.

We also have our minting API as a live product in beta; you can reach out to us to get access. If you want to skip all these steps, you can also create an NFT smart contract with one line of code, making it easy for anyone to produce NFT collections and expand the audience that can own them. Creators can use Crossmint for free, and we currently support Solana, Ethereum, Polygon, and Avalanche.

Follow us on Medium, so you are notified when we post another article! If you have any feedback, feel free to contact us via Twitter. You can always chat with us on our Discord community server, featuring some coolest developers you’ll ever meet.

--

--

Idowu Daniel
Crossmint Tech

Daniel is a Software Developer & Technical Writer. He is also a Web3 advocate passionate about the developers' community.