September 12, 2023

How to Get All NFT Tokens Owned by a User Address

Table of Contents

Today’s article will show you how to get a user’s NFT tokens list with the Moralis NFT API. Thanks to the power of this tool, you only need a single API call to the getWalletNFTs() endpoint to do so. Below, you can find the code showing an example of how it works in practice: 

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async () => {
  await Moralis.start({
    apiKey: "YOUR_API_KEY",
    // ...and any other configuration
  });

  const address = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";

  const chain = EvmChain.ETHEREUM;

  const response = await Moralis.EvmApi.nft.getWalletNFTs({
    address,
    chain,
  });

  console.log(response.toJSON());
};

runApp();

You simply need to add your Moralis API key, configure the address and chain parameters, and execute the code. In return, you’ll receive a response containing an array of NFTs. And it can look something like this:

{
  "total": 1456,
  "page": 1,
  "page_size": 100,
  "cursor": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21QYXJhbXMiOnsid2FsbGV0QWRkcmVzcyI6IjB4ZDhkYTZiZjI2OTY0YWY5ZDdlZWQ5ZTAzZTUzNDE1ZDM3YWE5NjA0NSJ9LCJrZXlzIjpbIjE2NjMyMzgxNzUuMDc3Il0sIndoZXJlIjp7Im93bmVyX29mIjoiMHhkOGRhNmJmMjY5NjRhZjlkN2VlZDllMDNlNTM0MTVkMzdhYTk2MDQ1In0sImxpbWl0IjoxMDAsIm9mZnNldCI6MCwib3JkZXIiOltdLCJ0b3RhbCI6MTQ1NiwicGFnZSI6MSwidGFpbE9mZnNldCI6MSwiaWF0IjoxNjY2NjgyNTUyfQ.E5DkWYvRTaFnVhgedRuT3IW-rb2V-ikFKwP2cg2Qf78",
  "result": [
    {
      "token_address": "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85",
      "token_id": "4765809967066625256798886812262830659450023020194524584471225959000376492819",
      "amount": "1",
      "owner_of": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
      "token_hash": "ba6d44b5f16be94283cecffeb784b7ca",
      "block_number_minted": "15572796",
      "block_number": "15573017",
      "contract_type": "ERC721",
      "name": "Ethereum Name Service",
      "symbol": "ENS",
      "token_uri": null,
      "metadata": null,
      "last_token_uri_sync": null,
      "last_metadata_sync": "2022-09-20T06:06:08.153Z",
      "minter_address": null
    },
    {
      "token_address": "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85",
      "token_id": "84453794918345416145331514647027903846664455083247396107154093349515123913389",
      "amount": "1",
      "owner_of": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
      "token_hash": "7c0212cd3daf1b6b64f193c6dc102fb4",
      "block_number_minted": "15572811",
      "block_number": "15573017",
      "contract_type": "ERC721",
      "name": "Ethereum Name Service",
      "symbol": "ENS",
      "token_uri": null,
      "metadata": null,
      "last_token_uri_sync": null,
      "last_metadata_sync": "2022-09-20T06:09:09.838Z",
      "minter_address": null
    }
  ],
  "status": "SYNCED"
}

To learn more about how this works, join us in this article as we break down the process in further detail. Or check out our official get NFTs by wallet documentation

Also, before we continue, don’t forget to sign up for free with Moralis to access the industry’s leading NFT API. In doing so, you can start leveraging the full power of the Web3 industry immediately and build your next NFT project in a heartbeat!  

Moralis Homepage - Sign Up to Get All NFT Tokens Owned By a User Address

Overview 

It doesn’t matter if you’re building a Web3 wallet, NFT marketplace, or a blockchain-based gaming platform; chances are you’ll need to fetch all NFT tokens owned by your users. However, to get a user NFT tokens list on a blockchain like Ethereum, you would have to parse the entire network, track ERC-721 smart contracts, and get the latest ownership data for each token. This requires a massive amount of engineering time and resources. Fortunately, you can now bypass this by leveraging the Moralis NFT API. To illustrate the power of this tool, we’ll take today’s article to show you how to get all tokens owned by a user address! 

However, before we dive into the main topic, we’ll kick things off by looking at what an NFT API is. From there, we’ll introduce the Moralis NFT API to highlight why this is the best tool to get a user NFT tokens list. After that, we’ll jump straight into the tutorial and show you how to get all NFT tokens owned by a user address in three steps: 

  • Step 1: Set up Moralis
  • Step 2: Call the getWalletNFTs() Endpoint
  • Step 3: Run the Code

If you’re already familiar with the ins and outs of NFT APIs, feel free to skip straight into the ”Get an NFT Tokens List of a User in 3 Steps” section! 

Lastly, we’ll top things off by exploring some prominent use cases where you need to get all NFTs owned by a user address.

If this sounds intriguing, join us in this article as we begin by jumping straight into the intricacies of NFT APIs!

What is an NFT API? 

An NFT API – short for application programming interface – is a set of protocols and rules allowing software systems to access and interact with on-chain data related to non-fungible tokens. One of the main points of an NFT API is to abstract the complexities of querying blockchain networks by introducing a developer-friendly interface that allows you to seamlessly acquire NFT-related data and integrate it into your projects.

API to Get User NFT Tokens List Example Graphic Art Image

NFT APIs generally offer a wide range of features, empowering developers to create innovative services and applications revolving around NFTs. You can find some common capabilities of NFT APIs below: 

  • Get NFTs Owned by Address: Most NFT API services allow you to seamlessly query the NFT balance of any address. 
  • Fetch NFT Metadata: NFTs usually have metadata attached to them. This information includes a title, description, and other attributes. With an NFT API, you can seamlessly get this information straight from the blockchain. 
  • Event Tracking: NFT APIs often provide real-time event tracking, allowing you to stay updated regarding various activities within the NFT space. This includes everything from new listings to token sales. 
  • Get Transfer Data: With an NFT API, you can get the latest NFT transfer data in real time. These interfaces also make it possible to query historical transaction data. 
  • Fetch Marketplace Data: Some NFT APIs support integrations with major marketplaces, allowing you to retrieve pricing data, information about trending collections, and more. 

Nevertheless, now that you have an overview of NFT APIs, let’s introduce you to the easiest way to get all tokens owned by a user address!

How to Get a User NFT Tokens List? 

There are multiple NFT APIs to choose from if you want to get a user NFT tokens list. However, your best option is Moralis’ industry-leading NFT API! 

The Moralis NFT API supports over three million NFT collections (and counting) across more than ten EVM-compatible chains. This includes established projects like CryptoPunks, Pudgy Penguins, etc., along with NFTs that dropped just a few seconds ago! 

NFT API to Get NFT Tokens List from Users Landing Page

So, what can you do with the NFT API? 

Thanks to the accessibility of this tool, you can, among other things, do the following with a single line of code: 

  • Get NFTs by Collection or Wallet: Simplify the development of your NFT projects by effortlessly fetching all NFTs from a given collection or wallet. 
  • Fetch NFT Metadata: Get NFT metadata, including a token’s name, description, images, traits, and more, with a single API call. If you’d like to learn more about this, check out our article on how to get ERC-721 on-chain metadata
  • Track NFT Trades by Marketplace: Stay informed about NFT marketplace dynamics by tracking tokens across major platforms like OpenSea and Rarible. 
  • Retrieve NFT Ownership Data: Retrieve and check NFT ownership data at the token or collection level with ease. 

To learn more about how the Moralis NFT API works and why this is the best option on the market, join us in the next section as we show you how to get a user NFT tokens list in three straightforward steps! 

Get a User NFT Tokens List in 3 Steps 

The Moralis NFT API is really easy to use, and to get a user NFT tokens list, all you need is a few lines of code and a single API call. To highlight this accessibility, we’ll show you how to get all NFTs owned by a user address in three steps:  

  • Step 1: Set up Moralis
  • Step 2: Call the getWalletNFTs() Endpoint
  • Step 3: Run the Code

But before we jump into the tutorial, you must deal with a couple of prerequisites! 

Prerequisites 

Before you can get a user NFT tokens list, you initially need to have the following installed and ready: 

  • Node v.14+
  • NPM/Yarn

Furthermore, you can also go ahead and set up a new project and open it with your integrated development environment (IDE). From there, open a new terminal and run the following command in the project’s root folder to install the Moralis SDK: 

npm install moralis @moralisweb3/common-evm-utils

That’s it for the prerequisites. You’re now ready to continue with the tutorial. As such, without further delay, let’s jump straight into the first step and show you how to set up Moralis! 

Step 1: Set Up Moralis 

Before you can make calls to the Moralis NFT API, you need access to your Moralis API key, and to get an API key, you need a Moralis account. That said, you can set up an account for free by clicking on the ”Start for Free” button at the top right of the Moralis homepage:  

Start for Free button Moralis

After setting up your account and your Moralis project, you can find your key by going to the ”Web3 APIs” tab and clicking on the ”Get your API keys” button: 

Accessing the NFT Tokens List API key page

This takes you to the following page, and you can go ahead and copy your API key and keep it for the second part: 

Showing how to copy the API key and paste into code to get user NFT tokens list

That’s it for the initial step. Let’s now show you how to implement the code for getting a user NFT tokens list! 

Step 2: Call the getWalletNFTs() Endpoint

For this tutorial, we’ll be using JavaScript to fetch all NFTs owned by a user address. As such, you can continue by creating an ”index.js” file in your project’s root folder. From there, you can copy and paste the code below: 

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async () => {
  await Moralis.start({
    apiKey: "YOUR_API_KEY",
    // ...and any other configuration
  });

  const address = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";

  const chain = EvmChain.ETHEREUM;

  const response = await Moralis.EvmApi.nft.getWalletNFTs({
    address,
    chain,
  });

  console.log(response.toJSON());
};

runApp();

Next, make sure to replace YOUR_API_KEY with the API key you copied in the previous step: 

Showing where to paste the API key for NFT tokens list

From here, add the wallet address you want to get the NFTs from to the address const and configure chain if you want to query another blockchain network:  

Showing how to modify address and chain parameters to get NFT tokens from a user

We then pass the address and chain constants as parameters when calling the getWalletNFTs() endpoint: 

Calling the GetUserNFTTokensList endpoint

That’s it! We only need a single API call to the getWalletNFTs() endpoint to get a user NFT tokens list when working with Moralis! 

From here, we just need to run the code above!

Step 3: Run the Code 

Running the code is simple, and you only need to open a new terminal, input the command below, and hit enter: 

node index.js

When you run the code, you’ll be provided with an array of NFTs looking something like this: 

{
  "total": 1456,
  "page": 1,
  "page_size": 100,
  "cursor": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21QYXJhbXMiOnsid2FsbGV0QWRkcmVzcyI6IjB4ZDhkYTZiZjI2OTY0YWY5ZDdlZWQ5ZTAzZTUzNDE1ZDM3YWE5NjA0NSJ9LCJrZXlzIjpbIjE2NjMyMzgxNzUuMDc3Il0sIndoZXJlIjp7Im93bmVyX29mIjoiMHhkOGRhNmJmMjY5NjRhZjlkN2VlZDllMDNlNTM0MTVkMzdhYTk2MDQ1In0sImxpbWl0IjoxMDAsIm9mZnNldCI6MCwib3JkZXIiOltdLCJ0b3RhbCI6MTQ1NiwicGFnZSI6MSwidGFpbE9mZnNldCI6MSwiaWF0IjoxNjY2NjgyNTUyfQ.E5DkWYvRTaFnVhgedRuT3IW-rb2V-ikFKwP2cg2Qf78",
  "result": [
    {
      "token_address": "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85",
      "token_id": "4765809967066625256798886812262830659450023020194524584471225959000376492819",
      "amount": "1",
      "owner_of": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
      "token_hash": "ba6d44b5f16be94283cecffeb784b7ca",
      "block_number_minted": "15572796",
      "block_number": "15573017",
      "contract_type": "ERC721",
      "name": "Ethereum Name Service",
      "symbol": "ENS",
      "token_uri": null,
      "metadata": null,
      "last_token_uri_sync": null,
      "last_metadata_sync": "2022-09-20T06:06:08.153Z",
      "minter_address": null
    },
    {
      "token_address": "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85",
      "token_id": "84453794918345416145331514647027903846664455083247396107154093349515123913389",
      "amount": "1",
      "owner_of": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
      "token_hash": "7c0212cd3daf1b6b64f193c6dc102fb4",
      "block_number_minted": "15572811",
      "block_number": "15573017",
      "contract_type": "ERC721",
      "name": "Ethereum Name Service",
      "symbol": "ENS",
      "token_uri": null,
      "metadata": null,
      "last_token_uri_sync": null,
      "last_metadata_sync": "2022-09-20T06:09:09.838Z",
      "minter_address": null
    }
  ],
  "status": "SYNCED"
}

Congratulations, you now know how to get a user NFT tokens list with Moralis! 

From here, you can now integrate this functionality into your future projects and start building more sophisticated NFT-based platforms! 

User NFT Tokens List – Use Cases 

The non-fungible attribute of NFTs makes them perfect for representing ownership of unique items. NFTs allow people to tokenize everything from digital art to real estate. This makes these tokens highly dynamic, and the technology is applicable in many situations. But when do you actually need to get all NFT tokens owned by a user address? To answer this question, we’ll explore three examples of prominent use cases when you need to get a user NFT tokens list!

Web3 Wallets 

Web3 wallets – also referred to as crypto wallets – are digital platforms for storing assets like fungible and non-fungible tokens. There are multiple prominent wallet providers, and some examples include MetaMask, Phantom Wallet, and Rainbow. 

Web3 wallets example of what to build using the NFT tokens list API

A good wallet needs to give users an overview of all their assets, meaning that these platforms need an easy and accessible way to fetch all tokens owned by a user address. Consequently, when building a Web3 wallet, an NFT API like the one Moralis offers can come in quite handy.

For instance, an already happy user of Moralis’ NFT API is the industry-leading Web3 wallet provider MetaMask:

DeFi Platforms 

Some DeFi platforms – which is an abbreviation for decentralized finance – use NFTs as collateral. On these platforms, users have the option to use their NFTs to borrow cryptocurrencies like DAI, USDC, etc. Some DeFi projects also provide additional features, such as the fractionalization of NFTs. 

If you’d like to learn more about this, please check out our article on fractional NFTs

In order to provide this functionality, DeFi platforms need to access the NFT balances of users, partly to display the tokens they hold. But also to allow users to actually put up their NFTs as collateral, fractionalize them, etc. Consequently, when building a DeFi platform like this, you need an easy way to get a user NFT tokens list.

NFT Marketplaces 

NFT marketplaces are digital platforms that allow users to store, sell, buy, display, and even mint NFTs. Some already existing marketplaces include Rarible, SuperRare, and OpenSea.

When building an NFT marketplace, you must be able to fetch the NFT tokens list of a user. This will, for instance, allow you to seamlessly display all tokens in their wallet so they know what assets they can list and sell.

To give you an even clearer example, check out the following testimonial from NFTrade – a prominent NFT marketplace already leveraging the Moralis NFT API:

Summary: How to Get the NFT Tokens List of a User with Moralis

In today’s article, we showed you how to get a user NFT tokens list with the Moralis NFT API in three steps: 

  • Step 1: Set up Moralis
  • Step 2: Call the getWalletNFTs() Endpoint
  • Step 3: Run the Code

Consequently, if you have followed along this far, you now know how to get all NFTs owned by a wallet address. From here, you can integrate this functionality into your future projects and build NFT-based applications in a heartbeat! 

If you liked this guide, consider checking out more content here at the Web3 blog. For instance, learn about OpenSea gas fees or dive into the ins and outs of a Linea Goerli faucet

You can also explore some additional tools Moralis offers. For example, check out the industry’s leading crypto Price API  and Web3 Wallet API, or learn how to set up Web3 webhooks with the Moralis Streams API

Also, don’t forget to sign up with Moralis to access these amazing development tools. You can create your Moralis account for free and start building your next project in the blink of an eye! 

NFT API
Unlock the full potential of your NFT projects with this industry-leading NFT API! Fast, easy, and free.
NFT API
Related Articles
December 31, 2022

Ethereum Logs and Events – What are Event Logs on the Ethereum Network?

March 10, 2023

How to Get Real-Time Crypto Wallet Balance Updates

November 2, 2022

Build with Dogecoin on EVM – What is Dogechain? 

January 30, 2023

OpenZeppelin in Remix – Importing OpenZeppelin Contracts in Remix

March 14, 2023

Notify Custom Webhooks – Real-Time Data with Moralis Streams

December 7, 2023

Which is the Best Crypto Exchange API for Web3 Developers?

January 22, 2023

Complete Tutorial on How to Create an ERC721 Token

January 19, 2023

Web3 Get Block Feature – Use a Web3 Get Block Timestamp Function