How to Get All the NFTs Owned by an Address

How to Get All the NFTs Owned by an Address

Takahashi Kaito

Takahashi Kaito

Chainbase Intern

Article Outline

  1. Introduction
  2. Tools required to work with Chainbase
  3. Set up a free account at Chainbase
  4. Write a script using Chainbase API
  5. Print NFTs owned by the wallet
  6. Conclusion
  7. FAQs (5 unique questions)

1. Introduction

As the world of Non-Fungible Tokens (NFTs) continues to gain popularity, it becomes essential for wallet owners to have the ability to view all the NFTs they hold. In this article, we will explore how you can retrieve all the NFTs owned by a specific wallet address using Chainbase, a platform that offers a convenient API endpoint called getAccountNFTs.

2. Tools Required to Work with Chainbase

Before we dive into the process, let's ensure we have the necessary tools in place:

  1. Chainbase Account and API Key: Start by setting up a free account at Chainbase and obtain an API key. This key will grant you access to the Chainbase API.
  2. Integrated Development Environment (IDE): For our examples, we will be using JavaScript, and you can use Visual Studio Code (VS Code) for writing and executing the code.
  3. Wallet Address: You will need a wallet address for which you want to obtain the associated NFTs. Make sure you have the address ready before proceeding.

3. Set up a Free Account at Chainbase

To make the most out of Chainbase's capabilities, begin by registering for a free account on our website. Once you've successfully logged in, explore the dashboard to familiarize yourself with the features. Next, create a new project using the console and obtain your unique API key.

4. Write a Script Using Chainbase API

Now that we have our account and API key, we can proceed with writing a script that utilizes the Chainbase API to retrieve the NFTs. Let's consider two options using JavaScript: fetch and axios.

Using Fetch in JavaScript


network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
wallet_addr = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'; // Take Vitalik's wallet address as an example.

fetch(`https://api.chainbase.online/v1/account/nfts?chain_id=${network_id}&address=${wallet_addr}&page=1&limit=5`, {
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
}).then(response => response.json())
    .then(data => console.log(data.data))
    .catch(error => console.error(error));

Using Axios in JavaScript

Ensure you have axios installed by running npm install axios --save in the terminal.


network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
wallet_addr = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'; // Take Vitalik's wallet address as an example.

const axios = require('axios');
const options = {
    url: `https://api.chainbase.online/v1/account/nfts?chain_id=${network_id}&address=${wallet_addr}&page=1&limit=5`,
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
};
axios(options)
    .then(response => console.log(response.data.data))
    .catch(error => console.log(error));

5. Print NFTs Owned by the Wallet

The Chainbase API provides the [getAccountNFTs](https://docs.chainbase.com/reference/getaccountnfts) endpoint, which requires the chain ID and the wallet address as parameters. This endpoint returns the NFTs associated with the given wallet address.

To secure and display the NFTs’ data, execute the script in your preferred JavaScript runtime environment. By running the command node <filename>.js in the terminal, you will see the NFTs owned by the provided wallet address.


[
  {
    contract_address: '0xc54567b294d7ec7807529fbaec71d326543453c5',
    erc_type: 'ERC721',
    image_uri: 'ipfs://QmVaTJSCgGFyfcd4hsaTN2ZMDh2hErpCtY9xMP9USdZqt1',
    metadata: {
      attributes: [Array],
      description: "CoinStats GLXY is for the starry-eyed and galaxy-brained. It's for those whose spaceship has landed on CoinStats planet, who appreciate the mysterious glow the cosmic entities on our orbit give off. Enjoy the kitsch!",
      image: 'ipfs://QmVaTJSCgGFyfcd4hsaTN2ZMDh2hErpCtY9xMP9USdZqt1',
      name: 'CoinStats GLXY 1856'
    },
    mint_time: '2022-08-11T07:22:13Z',
    mint_transaction_hash: '0x46a7b861a8f1e0290b6dc3095051bf03914701ea6b0a065455273c61fb6b3861',
    name: 'CoinStatsGLXY',
    owner: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
    symbol: 'GLXY',
    token_id: '0x0740',
    token_uri: 'ipfs://QmQyhH7CWpcRpZtuau7GzucbG4NnG2Uv3ZuAuvHGJWdys7/1856.json',
    total: 1,
    total_string: '1',
    traits: null
  },
  {
    contract_address: '0x495f947276749ce646f68ac8c248420045cb7b5e',
    erc_type: 'ERC1155',
    image_uri: '',
    metadata: null,
    mint_time: '0001-01-01T00:00:00Z',
    mint_transaction_hash: '',
    name: 'OpenSea Shared Storefront',
    owner: '',
    symbol: 'OPENSTORE',
    token_id: '0x92c6b6b4a1817e76b56eb3e1724f9df6026dd63c000000000000410000000006',
    token_uri: '',
    total: 1,
    total_string: '1',
    traits: null
  },
  {
    contract_address: '0x495f947276749ce646f68ac8c248420045cb7b5e',
    erc_type: 'ERC1155',
    image_uri: '',
    metadata: null,
    mint_time: '0001-01-01T00:00:00Z',
    mint_transaction_hash: '',
    name: 'OpenSea Shared Storefront',
    owner: '',
    symbol: 'OPENSTORE',
    token_id: '0x92c6b6b4a1817e76b56eb3e1724f9df6026dd63c000000000000400000000006',
    token_uri: '',
    total: 1,
    total_string: '1',
    traits: null
  },
  {
    contract_address: '0x495f947276749ce646f68ac8c248420045cb7b5e',
    erc_type: 'ERC1155',
    image_uri: '',
    metadata: null,
    mint_time: '0001-01-01T00:00:00Z',
    mint_transaction_hash: '',
    name: 'OpenSea Shared Storefront',
    owner: '',
    symbol: 'OPENSTORE',
    token_id: '0x92c6b6b4a1817e76b56eb3e1724f9df6026dd63c0000000000003f0000000006',
    token_uri: '',
    total: 1,
    total_string: '1',
    traits: null
  },
  {
    contract_address: '0x495f947276749ce646f68ac8c248420045cb7b5e',
    erc_type: 'ERC1155',
    image_uri: '',
    metadata: null,
    mint_time: '0001-01-01T00:00:00Z',
    mint_transaction_hash: '',
    name: 'OpenSea Shared Storefront',
    owner: '',
    symbol: 'OPENSTORE',
    token_id: '0x92c6b6b4a1817e76b56eb3e1724f9df6026dd63c0000000000003e0000000006',
    token_uri: '',
    total: 1,
    total_string: '1',
    traits: null
  }
]

API Reference If you want more detailed information about the [getAccountNFTs](https://docs.chainbase.com/reference/getaccountnfts) endpoint and its optional parameters, please refer to the official API documentation provided by Chainbase.

6. Conclusion

In this article, we explored how to get all the NFTs owned by a specific wallet address using the Chainbase API. We covered the necessary tools required to work with Chainbase, such as setting up a free account and obtaining an API key. Additionally, we provided examples of JavaScript code using both the fetch and axios libraries to make API requests.

By following the steps outlined in this article, you can easily retrieve the NFTs associated with any given wallet address. This functionality enables wallet holders to gain a comprehensive view of their NFT holdings, facilitating better management and analysis of their digital assets for developers.

If you have any further questions or face any challenges while implementing this process, please refer to the official Chainbase documentation or reach out to their support team for assistance.


7. FAQs

1. Is it necessary to have a Chainbase account to retrieve NFTs owned by a wallet address?

Yes, you need to have a Chainbase account and obtain an API key to access the [getAccountNFTs](https://docs.chainbase.com/reference/getaccountnfts) endpoint and retrieve NFTs associated with a wallet address.

2. Can I use a different programming language instead of JavaScript to retrieve NFTs using Chainbase?

Yes, Chainbase provides a RESTful API, so you can use any programming language that supports HTTP requests to interact with the Chainbase API and retrieve NFT data.

3. Can I retrieve all NFTs owned by any wallet address, or do I need specific permissions?

You can retrieve the NFTs owned by any wallet address as long as you have the wallet address and the necessary API key from Chainbase.

4. How can I increase the limit of NFTs retrieved per request?

In the API endpoint URL, you can modify the limit parameter to increase the number of NFTs retrieved per request. By default, it is set to 5 in the provided examples.

5. Are there any additional filters or sorting options available when retrieving NFTs using Chainbase?

Yes, Chainbase provides additional optional parameters in the [getAccountNFTs](https://docs.chainbase.com/reference/getaccountnfts) endpoint to apply filters and sorting options. You can refer to the official API documentation for more details on these parameters.


About Chainbase

Chainbase is an all-in-one data infrastructure for Web3 that allows you to index, transform, and use on-chain data at scale. By leveraging enriched on-chain data and streaming computing technologies across one data infrastructure, Chainbase automates the indexing and querying of blockchain data, enabling developers to accomplish more with less effort.

Want to learn more about Chainbase?

Visit our website chainbase.com Sign up for a free account, and Check out our documentation.

Website|Blog|Twitter|Discord|Link3