0%
Overview page background
HomeOverviewsNFTs
3 Important Reasons to Use Alchemy's NFT API for getNFTs

3 Important Reasons to Use Alchemy's NFT API for getNFTs

Alchemy headshot

Written by Alchemy

Brady Werkheiser headshot

Reviewed by Brady Werkheiser

Published on August 12, 20225 min read

If you’re building an NFT dApp, Alchemy’s NFT API can help you build better experiences for your users by using get requests, like getNFTs and getOwnersForToken. Let’s look at what these methods do and why we should use them in our NFT builds.    

getNFTs is an NFT API endpoint that allows developers to get the list of all NFTs, including ERC-721 and ERC-1155 tokens that belong to a particular owner address. You can enter either an owner address or an ENS name and the API will return the list of all NFTs owned by that address, along with the NFT metadata.

getNFTs is one of the most versatile NFT API endpoints, and can be used across a variety of web3 products including wallets to display NFTs, NFT marketplaces, NFT analytics tools, NFT rarity ranking sites, Discord bots, and many other use cases.

For example, if you were to go to the profile page of your OpenSea account, you would be able to see which NFTs you own. This is powered by an endpoint that uses getNFTs to return the NFTs owned by your wallet address and the related NFT metadata.

More broadly, getNFTs can benefit anything that requires you to either know what a user owns. For example, a getNFTs request could power NFT analytics tools like rarity ranking sites or a Discord bot by pulling in data and letting you know what NFT just sold, in which marketplace it sold, and any other relevant metadata.

getOwnersForToken is an API that allows you to specify an NFT smart contract and return the list of all owners for that token. For ERC-721 tokens, getOwnersForToken will only return a single owner, but for ERC-1155 tokens, which can have multiple owners, getOwnersForToken can return more than one wallet address.

getOwnersForToken has multiple use cases including airdrops, cache refreshes for NFT ownership changes, and profile picture verifications. 

If you’re running an NFT minting project and want to do an airdrop to owners of a specific token, getOwnersForToken allows you to identify this allowlist. 

Similarly, if you have a profile picture and want to verify ownership, you could use this API to check if ownership has changed.

Without getOwnersforToken, there is no convenient solution for these use cases because developers would have to parse the entire blockchain to figure out how the ownership for a single NFT has changed over time. Now, with Alchemy’s NFT API, the getOwnersForToken API can accomplish this task with one request.

Building with Alchemy's NFT API is the best choice for getting NFTs because of its coverage, spam filters, and image caching.

Alchemy's NFT API has the broadest coverage of NFTs, which is a challenge because NFT metadata lives on chain, off chain, and in inconsistent formats, which leads to a lot of edge cases for accurately logging metadata.

Having NFT metadata living in multiple different formats, and multiple different environments makes determining accurate metadata for an NFT a messy problem. 

Alchemy is able to provide the most complete NFT coverage because of designing multiple code paths to overcome many of the most prominent cases, including, but not limited to, handling metadata:

  • On chain or off-chain in JSON format

  • On chain or off-chain in SVG format

  • On chain or off-chain in UTF-8 format

Alchemy’s NFT API also can handle SVGs, NFTs that use IPFS gateways like Pinata, URIs pointing to an image to a secondary off-chain location, images encoded in base 64, and many other implementations.

Getting NFT metadata is a complicated process with many variations, but Alchemy’s NFT API offers a simple solution so you don’t need to waste valuable time thinking through each use case on its own. 

To get an NFT’s metadata, we start with an ID, which is a contract address and a token ID that together make up the unique identifier of the NFT.

This ID is checked against the Alchemy NFT cache to see if the information already exists. If it’s not in the cache, we need investigate what type of NFT it is and to what standard the contract conforms.

Alchemy currently supports two major NFT standards: ERC-721 and ERC-1155 smart contracts.

An actual ERC-721 standard should provide a scheme that has the NFTs title and properties, including the name, descriptions, and image, and be able to support some additional methods. 

In theory, you should be able to identify if an NFT does support this standard through a support interface call and the contract will respond with the answer. 

Because these contracts are programmable, a developer might intentionally or mistakenly program the contract to respond incorrectly, which means we need to look at other properties of the contract to ensure that it supports the interface. 

Once you’ve determined the smart contract is indeed an NFT, you can ask the contract or the token for the metadata’s location. For an ERC721 contract, the method you call is the token URI method, while for a 1155 contract, it is simply called the URI method.

The URI points to a place on the internet, or a place on-chain, where the NFT metadata exists. Some contracts, when asked for this location, point to a file, while others incorrectly provide the metadata directly in the token URI. 

If the URI points to another location, we’ll need to follow the link, most often to a third-party website or server, which has its own host of problems. These websites can be broken, malicious, or rate limited, but Alchemy cuts through that to cleanly return the information.

With some many different implementations across ERC-721 and ERC-1155 smart contracts, having broad and accurate data coverage of NFTs is a persistent challenge. Using the Alchemy NFT API is the best way to ensure maximum coverage of known NFTs.

Alchemy’s spam filter for getNFTs makes building even easier by filtering out spam NFTs, which are unsolicited airdrops or NFT smart contracts that break the ERC-721 and ERC-1155 standards.

In addition to the native filtering options of getNFTs, Alchemy’s new getSpamContracts will return the list of all ERC-721 and ERC-1155 spam contracts on the selected chain. 

Similarly, isSpamForContract will check if a particular NFT smart contract has been classified as spam. You can filter for contract addresses, which means you can also look for the owners of a particular NFT and check to see if that’s the only one they own.

Alchemy is the only platform with an NFT spam filter, and it is incredibly difficult to be engaging with NFTs if you’re being bogged down by spam.

Alchemy’s image caching leads to faster responses and faster load times for NFT images. While NFT media is traditionally served from IPFS, decentralized storage providers, or third-party servers, developers often face slow loading times and timeout errors when using these endpoints. Alchemy solves this problem by caching NFT images using Cloudinary and serving up NFT URLs from our own cache making retrievals quicker.

Because of Alchemy’s robust endpoints including spam filters, getFloorPrice, and reingestContract, the best NFT coverage, including support for Crypto Punks, and the most accurate data, the Alchemy NFT API is the best choice for web3 developers.

Sign up for an Alchemy account and see how Alchemy’s NFT API can help you build your next NFT project, or learn more about how Alchemy can help you in your web3 journey.

Overview cards background graphic
Desktop section background image

Build blockchain magic

Alchemy combines the most powerful web3 developer products and tools with resources, community and legendary support.

Get your API key