Skip to main content

Don't have an API key yet?

Sign-up to Moralis to get your free API key and start building today.

Get Your Free API Key
Version: 2.2

NFT API - Full Guide & Walkthrough

What is an NFT API?

An NFT API is a collection of APIs that can be used to index NFT data, e.g. NFT balance, NFT metadata, from multiple EVM chains that we support.

The NFT API is designed to provide high-quality, structured NFT data to developers to build application that interact with various kinds of NFTs (ERC721, ERC115, others).

Therefore, the ideal use cases for the NFT API are listed as below, but not limited to:

  • Portfolio dashboard
  • Wallets
  • NFT-gating applications (NFT-based tickets or memberships)
  • NFT marketplaces
  • etc.

The NFT API is divided into 6 categories based on their use cases as follows:

Get NFTs API

The Get NFTs API is a collection of NFT API that provides developer with all NFT stats (name, address, metadata, etc.) that fulfills certain search requirements, e.g. NFTs owned by a wallet, NFTs in a collection, NFTs with specific metadata, etc.

This API category comprised of 4 APIs:

API NamePathUse Cases
getMultipleNFTs/nft/getMultipleNFTsFetch a complete stats of multiple NFTs (max 25 per call) in a given tokens array.
getWalletNFTs/{address}/nftFetch all NFTs in a given wallet address. This is ideal for displaying NFT balance for a portfolio dashboard.
getContractNFTs/nft/{address}Fetch all tokens in a given NFT collection address.
searchNFTs/nft/searchFetch all NFT that have metadata that contains a given q string. This is ideal for building an NFT search functionality.

Get NFT Transfers API

The Get NFT Transfers API is a collection of NFT API that provides developer with various historical NFT transfers data.

This API category comprised of 5 APIs:

API NamePathUse Cases
getWalletNFTTransfers/{address}/nft/transfersFetch all transfers of NFT that interacted with a given address. This does not include any indirect NFT transfers, e.g. transferring NFT with OpenSea contract.
getNFTContractTransfers/nft/{address}/transfersFetch all transfers of a specific NFT collection with a given contract address.
getNFTTransfersFromToBlock/nft/transfersFetch all transfers of NFTs within the given from_block and to_block range. This is ideal for fetching NFT transfers from a specific range of time or block numbers.
getNFTTransfersByBlock/block/{block_number_or_hash}/nft/transfersFetch all transfers of NFTs in a given block_number_or_hash
getNFTTransfers/nft/{address}/{token_id}/transfersFetch all transfers of a specific NFT with given address and token_id.

Get NFT Collections API

The Get NFT Collections API is a collection of NFT API that provides developer with NFT collections-related data.

If an NFT collection has not been synced by the Moralis NFT API, it is also possible to manually index it by calling the syncNFTContract API.

This API category comprised of 3 APIs:

API NamePathUse Cases
getWalletNFTCollections/{address}/nft/collectionsFetch all NFT collection (not specific token) that is owned by a given address.
getNFTContractMetadata/nft/{address}/metadataFetch the NFT collection metadata (name, symbol, and contract type ERC721, ERC115, others) of a given address.
syncNFTContract/nft/{address}/syncManually sync to index an unindexed NFT collection with a given address.

Get NFT Owners API

The Get NFT Owners API is a collection of NFT API that provides developer with fetching and verifying ownership of certain NFT or NFT collections.

This API category comprised of 2 APIs:

API NamePathUse Cases
getNFTOwners/nft/{address}/ownersFetch all the token holders/owners of a given NFT collection with contract address. This can be used to verify NFT ownership for NFT-gating application.
getNFTTokenIdOwners/nft/{address}/{token_id}/ownersFetch all the token holders/owners of a given specific NFT token with contract address and token_id. This can be used to verify NFT ownership for NFT-gating application.

Get NFT Market Data API

The Get NFT Market Data API is a collection of NFT API that provides developer with all NFT market related-data, such as NFT historical trades and price.

This API category comprised of 2 APIs:

API NamePathUse Cases
getNFTTrades/nft/{address}/tradesFetch the list of trades of an NFT with a given contract address on OpenSea NFT Marketplace.
getNFTLowestPrice/nft/{address}/lowestpriceFetch the lowest price of an NFT with a given contract address on OpenSea NFT Marketplace.

Get NFT Metadata API

The Get NFT Metadata API is a collection of NFT API that provides developer with metadata of NFTs that would like to be indexed. This works out of the box with various types of NFTs (ERC721, ERC1155, others) and either on-chain or off-chain metadata.

This API comprised of 2 APIs:

API NamePathUse Cases
getNFTMetadata/nft/{address}/{token_id}Fetch the metadata (either off-chain or on-chain) a specific NFT with a given address and token_id.
reSyncMetadatanft/{address}/{token_id}/metadata/resyncResync/Update NFT metadata to its latest, if it dynamically changes.

How to get started?

To get started with Moralis NFT API, there are two methods that can be used, depending on the programming language that you are using:

Programming LanguagesMethod
JavaScript/TypeScript, PythonMoralis SDKs
Others (e.g. Java, C/C++, Ruby, etc.)REST API

For this guide, we'll particularly use the Moralis SDK for examples.

If you would like to use other languages calling the Moralis NFT API using regular REST API call, then make sure to check the NFT API reference pages to get all the parameters and responses type.

Step 1: Install the Moralis SDK

First register your Moralis account and get your Moralis API Key.

Once you have your Moralis API Key, install the Moralis SDK in your project.

npm install moralis

Step 2: Add to Your Code

To use the NFT API, it is very simple. All the NFT API can be called by using Moralis.EvmApi.nft.{apiName} where apiName will be replaced by the NFT API used.

In this guide, suppose you are building a simple NFT portfolio dashboard.

Let's start to use the NFT API to build these three initial features:

Feature #1: Fetch NFT balance of the user's wallet address

In order to fetch the NFT balance of the user's wallet address, Moralis provides you with a getWalletNFTs endpoint to do so.

Here you'll need two parameters: address and chain.

Once you've obtained both the address and chain, you can copy the following code and add it to your existing codebase:

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});

const address = "USER_WALLET_ADDRESS";

const chain = "CHAIN" // e.g EvmChain.ETHEREUM, EvmChain.POLYGON

const response = await Moralis.EvmApi.nft.getWalletNFTs({
address,
chain,
});

console.log(response.raw);
};

runApp();

Once the code is added, you will be able to obtain all the NFT that the user own in its wallet address using just a few lines of code with Moralis NFT API.

Feature #2: Fetch Historical NFT transfers that interacted with user's wallet address

In order to fetch the historical NFT transfers that interacted the user's wallet address, Moralis provides you with a getWalletNFTTransfers endpoint to do so.

Here you'll need two parameters: address and chain.

Once you've obtained both the address and chain, you can copy the following code and add it to your existing codebase:

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});

const address = "USER_WALLET_ADDRESS";

const chain = "CHAIN" // e.g EvmChain.ETHEREUM, EvmChain.POLYGON

const response = await Moralis.EvmApi.nft.getWalletNFTTransfers({
address,
chain,
});

console.log(response.raw);
};

runApp();

Once the code is added, you will be able to obtain the historical NFT transfers that interacted the user's wallet address using just a few lines of code with Moralis NFT API.

Feature #3: Fetch NFT lowest price from the NFT balance

In order to fetch the NFT price from the NFT balance, Moralis provides you with a getNFTLowestPrice endpoint to do so.

Here you'll need two parameters: address and chain.

Once you've obtained both the address and chain, you can copy the following code and add it to your existing codebase:

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});

const address = "NFT_CONTRACT_ADDRESS"; // provided from `getWalletNFTs`

const chain = "CHAIN" // e.g EvmChain.ETHEREUM, EvmChain.POLYGON

const response = await Moralis.EvmApi.nft.getNFTLowestPrice({
address,
chain,
});

console.log(response.raw);
};

runApp();

Once the code is added, you will be able to obtain the NFTs lowest price from the NFT balance using just a few lines of code with Moralis NFT API.

Step 3: Going Live!

Once you have a few lines of new code, you have successfully integrated the Moralis NFT API to your simple NFT portfolio dashboard app.

Now, it's time to push your code to production.

Before doing so, make sure that your API key is stored in a secure place. The best practice for this will be:

  • Storing your API key in an environment variable (secrets) process.env
  • Have your API called on the backend. While it is possible to call the NFT API on the fronted, it is highly discouraged as it can easily reveal your API key on the browser.

Once everything checks out, your app is good to go live with Moralis NFT API! 🚀