Everything You Need to Know About Alchemy's Optimism NFT API
Written by Mrig
Reviewed by Brady Werkheiser
NFT collections are surging on Optimism with more developers building new NFT dapps on the network. These developers need NFT APIs to query the network and obtain NFT metadata to fulfill user data requests. Without proper NFT APIs, indexing and querying NFT metadata becomes a time and resource-intensive procedure for individual developers.
Learn how to start building NFT tools, marketplaces, dapps, and more with Alchemy's Optimism NFT API.
Optimism’s NFT Ecosystem
Optimism is an L2 (layer 2) Ethereum scaling solution, running on optimistic rollup infrastructure. Optimistic rollups reduces the burden on Ethereum by conducting off-chain transactions, thereby offering higher transaction throughput and reduced gas fees. Optimistic rollups bundle multiple transactions into a single transaction, and sends them back to Ethereum for validation, thus enhancing network scalability.
Optimism’s in-built scalability makes it an ideal solution for developing NFT projects. Users get an enhanced experience for playing NFT games or trading collectibles with Optimism’s high-speed transactions and cheap fees.
With over 1 million NFT assets on Optimism spread over 238K NFT wallets according to the Optimism NFTScan website, developers require the right toolset to build NFT protocols and interact with a high volume of NFTs. Alchemy’s Optimism NFT API is a primary tool that developers need to build NFT projects for the Optimism ecosystem.
What is an Optimism NFT API?
The Optimism NFT API helps developers instantly fetch information from the L2 network. Developers can read block/transaction data, execute smart contracts, query on-chain information, and store data on-chain with Optimism NFT API.
Alchemy offers a multichain NFT API for developers that use the JSON-RPC standard APIs to interact with Optimism’s decentralized node infrastructure. Alchemy’s Optimism NFT API empowers developers to access higher request throughput, increase concurrent requests, and use free data archives, logs, and individual usage metrics. Further, the solution supports all NFTs following the ERC-721 and ERC-1155 standards, and selected NFTs that predated Ethereum’s standardized NFT contracts.
Developers also get access to a broad range of NFTs and their metadata through multiple code paths. Alchemy’s Optimism NFT API can handle on-chain or off-chain NFTs in JSON, SVG, UTF-8 format, IPFS gateways like Pinata, and encoded Base64 images.
Developers can use Alchemy’s NFT API for the following purposes:
Display NFTs to users
Develop an NFT marketplace
Design an NFT analytics protocol
Build NFT gaming applications
Verify NFT ownership
How does the Optimism NFT API work?
Alchemy’s Optimism NFT API uses the following mechanisms to achieve high performance functionality: image caching, spam filters, image resizing, and clear error descriptions.
Image Caching
Developers usually interact with decentralized storage providers like IPFS and third-party servers to access NFT media files. However, they face longer loading times and timeout errors.
Alchemy offers a low latency solution with fast loading and quick responses because it caches NFT images with Cloudinary. Thus, Alchemy can serve NFT URLs from their own cache to developers, thereby reducing response time.
Spam Filters
Unwanted spam NFTs can lead to scams and hinder user experiences in an NFT marketplace, gallery, or analytics platform. Developers usually have to read and parse individual smart contracts to access NFT metadata for filtering out spam NFTs. To help make things simpler, Alchemy offers the following API endpoints as NFT spam filters:
isSpamForContract - checks for spam NFT smart contracts. Developers can also filter contract addresses to check for owners of spam NFTs.
getSpamContracts - returns the list of spam ERC-721 and ERC-1155 smart contracts of a particular network.
Developers can use Alchemy’s spam filters to send spam NFTs for burning or flag wallet addresses that send spam NFTs. By August 2022, Alchemy NFT API had marked 5,000 smart contracts as spam NFTs.
Alchemy uses the following criteria to identify spam NFTs:
Breaks ERC-721 and ERC-1155 token standards
Breaks token standards during token transfers
Mint tokens to honeypot addresses like vitalik.eth
Provides false data about the total token supply
Image Resizing
NFTs need different image sizes for thumbnails, smartphones, desktops, and tablet viewports. Developers can resize Alchemy-hosted NFTs by changing URLs to include any combination of height and width pixels to create the aspect ratio. Thus, Alchemy makes image resizing easier for NFT developers.
NFT Errors
Although Alchemy’s NFT API returns most NFT metadata, it fails to fulfill the request in the following instances:
Token does not exist - Alchemy uses a token ID to call the tokenURI/uri method, but the smart contract cannot recognize it. It either means the token isn’t minted yet or it doesn’t exist.
Malformed token URI - tokenURI/uri returns a ‘malformed’ or invalid website, and therefore cannot access the website to return metadata.
Failed to get token URI - generic error message when the token ID doesn’t return any metadata, even if the token exists.
Token URI returns a non-200 response code - this error shows when the URI returns a ‘502 Bad Gateway’ message if the website is down or it rate-limits Alchemy servers.
Throttled token URI - this error returns a ‘429 Too Many Requests’ message, indicating Alchemy has requested metadata too frequently, thereby getting rate-limited.
Contract does not have any code - this error shows when a token address doesn’t have a corresponding smart contract code on the blockchain network.
Contract returned a broken token URI, do not retry - this error message shows when the tokenURI doesn’t respond because the website URL may not exist, or lacks DNS setup.
Optimism NFT API Supported Methods
Alchemy’s Optimism NFT API helps developers to build Optimism NFT dapps with the following categories of NFT API endpoints:
Optimism NFT Ownership and Token Gating
getNFTs - get Optimism NFTs owned by a wallet
getOwnersForToken - get Optimism owners for a token
getOwnersForCollection - get Optimism NFT owners for collection
isHolderOfCollection - check if the Optimism wallet holds an NFT
getNFTsForCollection - get NFTs for Optimism NFT collection
Optimism NFT Metadata
getNFTMetadata - get Optimism NFT metadata
getContractMetadata - get Optimism NFT smart contract metadata
Optimism NFT API Examples
Alchemy’s getNFTs is a versatile NFT API endpoint is a versatile NFT API endpoint, enabling developers to use it in multiple NFT protocols. To understand how the getNFTs API endpoint functions, consider the following examples.
1. Optimism Token Gating
When developers build an NFT marketplace, they design a user profile page that displays user-owned NFTs. Developers can use the Optimism NFT token gating tool, isHolderOfCollection, to fetch NFTs from a particular wallet address is they hold a particular token from a specified collection.
2. Optimism NFT Analytics Tool
NFT analytics tools like rarity ranking websites or aggregators require NFT metadata to create lists and obtain trading data. Developers can use the Optimism NFT metadata API, getNFTMetadata, to retrieve the on-chain metadata used in NFT analytics tools.
3. Optimism NFT Airdrop Lists
An NFT project hires developers to airdrop new NFTs to owners of a specific NFT. Without an API, developers have to parse the whole blockchain to trace NFT asset ownership. However, Alchemy’s Optimism NFT collection API, getOwnersForToken, enables developers to instantly identify owners and create the airdrop list. Developers can also use this API to verify asset ownership when users want to put up a particular NFT as their profile picture.
How to Start Building with the Optimism NFT API
Instead of running your own Optimism node, it’s easy to create a private Optimism node on Alchemy, and then follow three easy steps to start building with Alchemy’s Optimism NFT API:
Choose a package manager - use a package manager like npm or yarn
Setup the repo - open a terminal to create a new repository from the command line for the quickstart scripts
Choose a library - install the Alchemy SDK to interact with the Optimism NFT API
Although developers can use Fetch and Axios, the quickest way to start using the Optimism NFT API is with Alchemy’s SDK because it offers better facilities with WebSocket support, retries, and many other benefits.
Use the Best Optimism NFT API with Alchemy
During the 2021 bull run, the NFT market surpassed $40 billion according to Bloomberg. Although the NFT sector is currently going through a tough bear market phase, NFT technology holds immense potential for future growth.
Therefore, builders will need the right NFT developer tools to create their NFT dapps on the scalable Optimism network. Create a free account on Alchemy and start building NFT dapps with Alchemy’s free NFT API.
Related overviews
How to Find, Label, and Filter Spam NFTs with Alchemy's NFT API
Learn How Sellers Set Terms for NFT Sales and Buyers Finance NFT Purchases Over Time
Learn About NFT Minting Platforms and Their Benefits for Creators