How to Check the Owner of an NFT (2024)

📘

API Endpoint

This tutorial uses the getOwnersForToken endpoint.

If you just need the script for this tutorial refer to the below Recipe or continue reading for more

🖼️

Script to check the owner of an NFT

Open Recipe

One of the most fundamental aspects of an NFT is ownership.

Whether you're building an NFT marketplace like OpenSea, a web3 wallet like Rainbow, or an analytics platform like rarity.tools, knowing who owns an NFT is important information.

How to Check the Owner of an NFT (1)

An NFT can have a single owner (ERC-721) or multiple owners (ERC-1155).

Typically, getting ownership data on an NFT requires you to:

  1. spin up a node
  2. call functions on the NFT contract
  3. parse the output

Now, getting a list of owners for an NFT collection takes one API call using Alchemy's NFT API.

In this tutorial, we will write a script in Node.js that tells us who the owner of an NFT is using the NFT API. In this example, we will use an NFT called Safe Haven from the TIMEPieces collection.

Before you begin, complete the following steps to set up your web3 developer environment.

1. Install Node.js (> 14) on your local machine

2. Install npm on your local machine

To check your Node version, run the following command in your terminal:

node -v

3. Create a free Alchemy account

Step 1: Create a new Alchemy app

To create an Alchemy app, check out this video or follow the instructions below:

  1. From Alchemy's dashboard, hover over the Apps drop-down menu and choose Create App.
  2. Provide a Name and Description for your app.
  3. For Chain, select Ethereum and for Network select Goerli.
  4. Click the Create App button.
How to Check the Owner of an NFT (2)

Once you have created your app, get your API key that we will use later in this tutorial.

  1. Click on your app's View Key button in the dashboard
  2. Copy and save the API KEY

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

To make requests to the NFT API, we recommend using the Alchemy SDK Quickstart.

However, you can also use the axios or fetch libraries. We provide code samples for each

From your terminal, run the following commands:

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

This will create a repository named nft-owner that holds all the files and dependencies we need.

Open this repo in your preferred code editor, where we'll write our code in the main.js file.

Step 3: Find the owner of an NFT

To get the owner of a single NFT, use the getOwnersForToken function.

This function accepts two required arguments.

  1. contractAddress: The NFT's smart contract address (ERC-721 or ERC-1155)
  2. tokenId: The ID of the NFT (decimal or hexadecimal format)

We require these two arguments because any NFT on any blockchain can be uniquely identified only by specifying both its contract address and token ID.

For more information, check out the NFT API QuickStart.

Next, add the following code to the main.js file, using your Alchemy API key:

// Setup: npm install alchemy-sdkimport { Alchemy, Network } from "alchemy-sdk";const config = { apiKey: "<-- ALCHEMY APP API KEY -->", network: Network.ETH_MAINNET,};const alchemy = new Alchemy(config);const main = async () => { // TIMEPieces contract address const address = "0xDd69da9a83ceDc730bc4d3C56E96D29Acc05eCDE"; // Safe Haven Token ID const tokenId = 4254; // Get owner of NFT const owner = await alchemy.nft.getOwnersForNft(address, tokenId); console.log(owner);};const runMain = async () => { try { await main(); process.exit(0); } catch (error) { console.log(error); process.exit(1); }};runMain();
const axios = require('axios')// TIMEPieces contract addressconst address = '0xDd69da9a83ceDc730bc4d3C56E96D29Acc05eCDE'// Safe Haven Token IDconst tokenId = 4254// Alchemy API keyconst apiKey = '<-- ALCHEMY APP API KEY -->';// Alchemy URLconst baseURL = `https://eth-mainnet.g.alchemy.com/nft/v2/${apiKey}/getOwnersForToken`;const url = `${baseURL}?contractAddress=${address}&tokenId=${tokenId}`;const config = { method: 'get', url: url,};axios(config) .then(response => console.log(response.data)) .catch(error => console.log(error));
import fetch from 'node-fetch';// TIMEPieces contract addressconst address = '0xDd69da9a83ceDc730bc4d3C56E96D29Acc05eCDE'// Safe Haven Token IDconst tokenId = 4254// Alchemy API keyconst apiKey = '<-- ALCHEMY APP API KEY -->';// Alchemy URLconst baseURL = `https://eth-mainnet.g.alchemy.com/nft/v2/${apiKey}/getOwnersForToken`;const url = `${baseURL}?contractAddress=${address}&tokenId=${tokenId}`;var requestOptions = { method: 'get', redirect: 'follow'};fetch(url, requestOptions) .then(response => console.log) .catch(error => console.log('error', error))

Run this script by running the following command in your terminal:

node main.js

If successful, you should see output that looks something like this:

{ owners: [ '0xc9391d1ea5d092f774cf66312a9a347aaedf95a5' ] }

Since the NFT we were interested in was of the ERC-721 standard, we retrieved an array with only a single wallet address as the owner.

If we were retrieving information for an ERC-1155 NFT, which can have multiple owners, the array might contain multiple wallet addresses.

You now know how to use the Alchemy NFT API to check the owner of an NFT.

If you enjoyed this tutorial about how to get all NFTs owned by an address, tweet us at @AlchemyPlatform and give the authors @rounak_banik and @ankg404 a shoutout!

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

Updated almost 2 years ago

How to Check the Owner of an NFT (2024)
Top Articles
REITs vs. Rental Property: Which Strategy Should You Choose?
Friendship
Www.paystubportal.com/7-11 Login
English Bulldog Puppies For Sale Under 1000 In Florida
Craigslist Pets Longview Tx
East Cocalico Police Department
2024 Fantasy Baseball: Week 10 trade values chart and rest-of-season rankings for H2H and Rotisserie leagues
CKS is only available in the UK | NICE
Best Private Elementary Schools In Virginia
Acbl Homeport
Boat Jumping Female Otezla Commercial Actress
What is the difference between a T-bill and a T note?
Foodland Weekly Ad Waxahachie Tx
Jesus Calling Oct 27
50 Shades Darker Movie 123Movies
Kürtçe Doğum Günü Sözleri
ZURU - XSHOT - Insanity Mad Mega Barrel - Speelgoedblaster - Met 72 pijltjes | bol
I Saysopensesame
2024 INFINITI Q50 Specs, Trims, Dimensions & Prices
Yonkers Results For Tonight
What Is The Lineup For Nascar Race Today
Haunted Mansion Showtimes Near Epic Theatres Of West Volusia
Delectable Birthday Dyes
Makemv Splunk
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
11526 Lake Ave Cleveland Oh 44102
When His Eyes Opened Chapter 3123
Motorcycle Blue Book Value Honda
Tactical Masters Price Guide
Maths Open Ref
The Creator Showtimes Near Baxter Avenue Theatres
Hannah Jewell
How To Make Infinity On Calculator
404-459-1280
Rise Meadville Reviews
Download Diablo 2 From Blizzard
Craigslist Boats Dallas
10 Rarest and Most Valuable Milk Glass Pieces: Value Guide
How to Quickly Detect GI Stasis in Rabbits (and what to do about it) | The Bunny Lady
Conan Exiles Armor Flexibility Kit
Shoecarnival Com Careers
Senior Houses For Sale Near Me
Matt Brickman Wikipedia
Hampton In And Suites Near Me
Canada Life Insurance Comparison Ivari Vs Sun Life
Hello – Cornerstone Chapel
Market Place Tulsa Ok
Colin Donnell Lpsg
The 5 Types of Intimacy Every Healthy Relationship Needs | All Points North
Autozone Battery Hold Down
Craigslist Yard Sales In Murrells Inlet
How to Choose Where to Study Abroad
Latest Posts
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 6233

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.