APIs used:
  • Check ownership in NFT collection  
  • Check ownership in NFT collection for specific token  

NFT Ownership

NFTs, or non-fungible tokens, are unique digital assets verified using blockchain technology. Commonly, NFT ownership provides a new way to invest in and collect digital art, music, and other forms of media. Proof of ownership is on-chain and gives the owner exclusive rights to sell or trade the asset. This verification ensures that the asset is one-of-a-kind and allows it to be verified and trusted by the community making it valuable to collectors, creators, and investors. It can also lead to profits if the NFT appreciates in value.

Use Cases for Developers

NFT ownership data is essential anytime a business or individual wants to verify that someone owns what they say they do. In Web3, there are many emerging ways to use NFT ownership as a means for exclusive access, rewards, information and more. Here are some use cases for developers:

  • Token gating: Web3 events are often “token gated,” meaning they are only accessible to people who hold a particular NFT. This could be for parties, meetings, conferences, votes in a governance forum and more.

  • Course completion: NFTs can be used as certificates or awards to verify that an individual has completed some form of learning.

  • On-chain identity: There are many emerging tools where individuals can showcase their POAPs (proof of attendance protocol), NFTs they hold, DAOs they are part of and more. Additionally, Soulbound Tokens (digital identity tokens that represent a person’s traits or achievements) can be issued by “Souls” (blockchain accounts or wallets). Soulbound Tokens cannot be transferred.

  • Messaging and Newsletters: NFTs can send information to groups of people on the blockchain. This could be in the form of fun messages, subscription newsletters, or magazines. This method of communication allows readers to verify the source of their information and combat “fake news” claims.

Whatever the case, Covalent makes it easy to check and verify ownership in a given NFT collection or for a specific NFT. Keep reading to learn how!

Checking NFT Ownership in a Collection

(Est time to follow along: 5 mins)

Step 1: Sign up or sign in

Sign up for an API key if you haven’t gotten one yet.

Step 2: Find the API Reference

Once signed up, navigate to the API Reference page. This is where you can try out all the Covalent endpoints live.

Step 3: Find the Ownership and Token Gating endpoints

Where you see the list of API endpoints, go to CLASS A > NFT > Ownership and Token Gating. The endpoints we are interested in are:

The first endpoint is used to check if a wallet holds any NFT(s) from a particular collection, whereas the second endpoint checks if a wallet is holding a specific NFT (requires token ID).

Step 4: Construct your API call

To check if a wallet owns an NFT from a certain collection, we will need the owner’s wallet address (walletAddress), the contract address for the NFT collection (collectionContract), and the name of the blockchain that the collection is on (chainName). In this example, let’s say that Invisible Friends has a party where they only want to invite holders of their NFTs. In this hypothetical scenario, they commission you to build a custom event platform that checks the wallet of everyone who RSVPs to their parties. With Covalent, this is super easy.

From Opensea or Etherscan, we can get the contract address of the NFT collection 0x59468516a8259058baD1cA5F8f4BFF190d30E066. We also find that this collection is on Ethereum, so we will use eth-mainnet as the chainName parameter. Now we only need to input the wallet address of whoever RSVPs to this party.

Step 5: Hit Run

Now, someone RSVPs to this party with their ENS, polkaguy.eth. The Covalent API actually resolves ENS names, so you can input polkaguy.eth right into the walletAddress parameter of your query and hit Run.

Sample Response

This query returns the following response:

json
{
  "data": {
    "updated_at": "2023-03-23T21:07:43.925663471Z",
    "address": "polkaguy.eth",
    "collection": "0x59468516a8259058bad1ca5f8f4bff190d30e066",
    "items": [
      {
        "contract_address": "0x59468516a8259058bad1ca5f8f4bff190d30e066",
        "contract_name": "Invisible Friends",
        "contract_ticker_symbol": "INVSBLE",
        "supports_erc": [
          "erc20",
          "erc721"
        ],
        "token_id": "4626",
        "last_transfered_at": "2023-03-21T12:03:47Z",
        "balance": 1,
        "balance24h": 1,
        "type": "nft",
        "nft_data": {
          "token_id": "4626",
          "token_url": "https://ipfs.io/ipfs/QmarGRwVKPaCe2s5QSSTMEdbYDwKxFz6bAn58YZPPcWc7k/4626",
          "original_owner": null,
          "external_data": {
            "name": "Invisible Friends #4626",
            "description": "5,000 animated Invisible Friends hiding in the metaverse. A collection by Markus Magnusson & Random Character Collective.",
            "asset_url": "https://nftassets.covalenthq.com/b05da43d935ff1e45db5fbbdf195b0fae43a6f08803deabf35115bd3a1450717.gif",
            "asset_file_extension": "gif",
            "asset_mime_type": "image/gif",
            "asset_size_bytes": "1195147",
            "image": "https://nftassets.covalenthq.com/b05da43d935ff1e45db5fbbdf195b0fae43a6f08803deabf35115bd3a1450717.gif",
            "image_256": "https://nftassets.covalenthq.com/cdn-cgi/image/width=256,fit/b05da43d935ff1e45db5fbbdf195b0fae43a6f08803deabf35115bd3a1450717.gif",
            "image_512": "https://nftassets.covalenthq.com/cdn-cgi/image/width=512,fit/b05da43d935ff1e45db5fbbdf195b0fae43a6f08803deabf35115bd3a1450717.gif",
            "image_1024": "https://nftassets.covalenthq.com/cdn-cgi/image/width=1024,fit/b05da43d935ff1e45db5fbbdf195b0fae43a6f08803deabf35115bd3a1450717.gif",
            "animation_url": null,
            "external_url": null,
            "attributes": [
              {
                "trait_type": "Feet",
                "value": "Bubblegum Blue Sneakers"
              },
              {
                "trait_type": "Legs",
                "value": "White Sweatpants"
              },
              {
                "trait_type": "Upper Body",
                "value": "Grey Zipper Hoodie with Hood Down"
              },
              {
                "trait_type": "Sleeves",
                "value": "Long Sleeves"
              },
              {
                "trait_type": "Hat",
                "value": "Red Headband"
              },
              {
                "trait_type": "Eyes",
                "value": "Black Glasses"
              },
              {
                "trait_type": "Mouth",
                "value": "Bing Bong Stick"
              },
              {
                "trait_type": "Ears",
                "value": "Earrings"
              },
              {
                "trait_type": "Right Arm",
                "value": "Swinging"
              },
              {
                "trait_type": "Left Arm",
                "value": "Swinging"
              },
              {
                "trait_type": "Background",
                "value": "Purple"
              }
            ]
          }
        }
      }
    ]
  },
  "error": false,
  "error_message": null,
  "error_code": null
}

The JSON response tells us that polkaguy.eth does indeed hold an NFT in the Invisible Friends collection. It also tells us exactly which NFT and all its external metadata! They have Invisible Friends #4626, which we can render and examine its attributes from the data returned.

In this case, we aren’t worried about which NFT someone holds but verifying that they hold any NFT in this collection. However, if we wanted to see if polkaguy.eth had this specific NFT, we could use the Check ownership in NFT collection for specific token endpoint. After inputting the tokenId as 4626, we would get a similar response.

Sample Code

Here is some sample code that helps verify whether a user holds an any NFTs from a specific contract:

jsx
const apiKey = //insert your API key here

const isOwner = (walletAddress, collectionContract) => {
    const checkOwnershipEndpoint = `https://api.covalenthq.com/v1/eth-mainnet/address/${walletAddress}/collection/${collectionContract}/`
	fetch(checkOwnershipEndpoint, {method: 'GET', headers: {
      "Authorization": `Basic ${btoa(apiKey + ':')}`
    }})
      .then(res => res.json())
      .then(res => {
				if (res.data.items.length > 0) {
					console.log(`Address ${walletAddress} is an owner of ${res.data.items.length} ${res.data.items[0].contract_name} NFT/NFTs`)
				} else {
					console.log(`User does not own any NFTs within the collection.`)
				}
      })
}

isOwner('polkaguy.eth', '0x59468516a8259058bad1ca5f8f4bff190d30e066')

Conclusion

In conclusion, NFT ownership allows collectors and investors to own unique digital assets that cannot be duplicated or copied. It also enables creators to monetize their digital work, potentially leading to profits if the NFT appreciates. Furthermore, NFT ownership has many emerging use cases in Web3, providing new ways for developers to use NFTs for exclusive access, rewards, and identity verification. Covalent makes it easy for developers to check and verify ownership in a given NFT collection or for a specific NFT. With the continued growth of the NFT market, the importance of NFT ownership will only continue to rise as more use cases emerge.

Check out our other NFT endpoints to get NFT metadata, transactions, traits, attributes, and more!