How to do Holder Snapshots for Your NFT Collection on NEAR Blockchain

Jacob HoekertJacob Hoekert
Mar 13, 2023|2 min read

If you're an NFT collection owner who wants to get a list of every wallet that holds your NFT on NEAR, this tutorial is for you! We'll guide you through building a GraphQL query using the indexer.xyz interface that will allow you to get a list of holders for your NFT collection.

Prerequisites

To follow along with this tutorial, you'll need to have a basic understanding of GraphQL and the indexer.xyz interface. If you're new to GraphQL, check out this resource to learn the basics.

Building the Query

Let's start by breaking down the query that we'll be building:

query MyQuery {
  near {
    collection(where: {slug: {_eq: "asac.near"}}) {
      slug
      nft_metas {
        nft_state {
          owner
          staked_owner
        }
      }
    }
  }
}

This query is designed to retrieve information about all wallets that hold your NFT collection on the Near Protocol blockchain.

Query Breakdown

Here's a breakdown of the different parts of the query:

  • query MyQuery: This is the name of the query we're running.
  • near: This is the root query for the Near Protocol blockchain data.
  • collection: This is the sub-query that will return the collection data.
  • where: This is a filter for the collection query. Here, we're filtering by:
  • slug: {_eq: "asac.near"}: This filters the results to only include the specified collection.
  • nft_metas: This is a sub-query that will return metadata about the NFTs in the collection.
  • nft_state: This is a sub-query that will return the state of the NFT.
  • owner and staked_owner: These are the specific fields that we're requesting information for. In this case, we're asking for the wallet address of the owner and staked owner of each NFT.

Customizing the Query

To customize this query to get a list of holders for your own NFT collection, you'll need to update the slug field within the where clause. Simply replace asac.near with the slug of your NFT collection.

Running the Query

Now that we have our query built, let's run it using the indexer.xyz interface:

  1. Navigate to the indexer.xyz website.
  2. In the top right corner of the page, click the "API Explorer" button to open the query editor.
  3. In the query editor, paste the query we just built.
  4. Click the "play" button in the top left corner of the editor to run the query.
  5. Once the query has run, you'll see a JSON response with the wallet addresses of the owners and staked owners of the NFTs in your collection.
{
  "data": {
    "near": {
      "collection": [
        {
          "slug": "asac.near",
          "nft_metas": [
            {
              "nft_state": {
                "owner": "ispytodd.near",
                "staked_owner": null
              }
            },
            {
              "nft_state": {
                "owner": "jellyyy.near",
                "staked_owner": null
              }
            },
            {
              "nft_state": {
                "owner": "drcryptog.near",
                "staked_owner": null
              }
            },
            {
              "nft_state": {
                "owner": "staking.paras.near",
                "staked_owner": "bigbraine.near"
              }
            } 
            ... ]
           }
      }
  }

Conclusion

Using the indexer.xyz interface and a customized GraphQL query, you can easily get a list of wallets that hold your NFT collection. By filtering the results using the where clause and specifying which fields you want to retrieve, you can get detailed information about your NFT collection holders. Happy collecting!