The NFT API removes all the difficulties from working with NFTs and integrating NFTs into your dapps.
Working with NFTs is normally difficult as NFT token standards are poorly followed and a lot of edge-cases arise when you start parsing on-chain NFT data.
That's why the NFT API was built to provide a unified interface for all NFT tokens across different blockchains so that you can focus on your dapp without running your own NFT parsing pipeline.
The most important use-cases for this API is getting cross-chain data related to:
NFT Metadata
NFT Ownership data
NFT Transfer data
NFT Prices
NFT API Specification
Chain supported:
Ethereum (ETH)
Binance Smart Chain (BSC)
Polygon (MATIC)
Avalanche (AVAX)
Fantom (FTM)
Testnets are fully supported.
Endpoints:
searchNFTs
Very powerful and fast tool for getting the NFT data based on a metadata search (asynchronous).
Options:
chain(optional): The blockchain to get data from. Valid values are listed on Supported Chains. Default value Eth.
format (optional): The format of the token id. Available values : decimal, hex. Default value : decimal.
cursor (optional): The next page of data to retrieve. Next page cursor value returned from each request.
limit(optional): limit (max 100).
q (required): The search string parameter
filter(required): What fields the search should match on. To look into the entire metadata set the value to global. To have a better response time you can look into a specific field like name. Available values : name; description; attributes; global; name,description; name,attributes; description,attributes; name,description,attributes
"result": [ { token_id:"854645", token_address:"0xdf7952b35f24acf7fc0487d01c8d5690a60dba07", token_uri:"https://ipfs.moralis.io:2053/ipfs/QmYUHFzEvPsoseNWcHtqE18Ao8HPBRktLPoDMKpdDYvHQV", metadata: "{\n \"name\": \"Pancake Christmas 2021\",\n \"description\": \"A great collab between Chef Cecy and the winner of the #PancakeChristmas event. Merry Christmas, and Happy New Year!\",\n \"mp4_url\": \"ipfs://QmXYFMtYVBJBKjgGwf6MmrKhVtNdbVjLQCPLCu99hpAu47/christmas-2021.mp4\",\n \"gif_url\": \"ipfs://QmXYFMtYVBJBKjgGwf6MmrKhVtNdbVjLQCPLCu99hpAu47/christmas-2021.gif\",\n \"webm_url\": \"ipfs://QmXYFMtYVBJBKjgGwf6MmrKhVtNdbVjLQCPLCu99hpAu47/christmas-2021.webm\",\n \"image\": \"ipfs://QmXYFMtYVBJBKjgGwf6MmrKhVtNdbVjLQCPLCu99hpAu47/christmas-2021.png\",\n \"attributes\": {\n \"bunnyId\": \"23\"\n }\n}",
is_valid:1, syncing:2, frozen:0, resyncing:0, synced_at:"2022-01-02T19:50:58.391Z", contract_type:"ERC721", token_hash:"fffedca3037a8dc03483193b99fa9736", batch_id:null, metadata_name:"\"Pancake Christmas 2021\"", metadata_description: "\"A great collab between Chef Cecy and the winner of the #PancakeChristmas event. Merry Christmas, and Happy New Year!\"",
metadata_attributes:"{\"bunnyId\":\"23\"}", block_number_minted:"14022006", opensea_lookup:null, minter_address:"0xd338d2d63b55cbb059162394544a473156d513bd", transaction_minted:"0xd7d0651c5bdf168c83f7a7e6570345bf73b11aabee3da7a6a3126034a77e382d", frozen_log_index:null, imported:null, createdAt:"2022-01-02T19:49:52.234Z", updatedAt:"2022-01-02T19:49:52.234Z" }
getNFTs
Get all NFTs from the current user or address. Supports both ERC721 and ERC1155. Returns an object with the number of NFT objects and the array of NFT objects (asynchronous).
Options:
chain(optional): The blockchain to get data from. Valid values are listed on Supported Chains. Default value Eth.
address (optional): A user address (i.e. 0x1a2b3x...). If specified, the user attached to the query is ignored and the address will be used instead.
// get NFTs for current user on MainnetconstuserEthNFTs=awaitMoralis.Web3API.account.getNFTs();// get testnet NFTs for userconsttestnetNFTs=awaitMoralis.Web3API.account.getNFTs({ chain:"goerli" });// get polygon NFTs for addressconstoptions= { chain:"polygon", address:"0x75e3e9c92162e62000425c98769965a76c2e387a",};constpolygonNFTs=awaitMoralis.Web3API.account.getNFTs(options);
import React from"react";import { useMoralisWeb3Api } from"react-moralis";constWeb3Api=useMoralisWeb3Api();constfetchNFTs=async () => {// get NFTs for current user on MainnetconstuserEthNFTs=awaitWeb3Api.account.getNFTs();console.log(userEthNFTs);// get testnet NFTs for userconsttestnetNFTs=awaitWeb3Api.Web3API.account.getNFTs({ chain:"goerli", });console.log(testnetNFTs);// get polygon NFTs for addressconstoptions= { chain:"polygon", address:"0x75e3e9c92162e62000425c98769965a76c2e387a", };constpolygonNFTs=awaitWeb3Api.account.getNFTs(options);};console.log(polygonNFTs);
Returns an object with the NFT count for the specified contract and an NFT array belonging to the given address for the specified contract (asynchronous).
Options:
chain(optional): The blockchain to get data from. Valid values are listed on Supported Chains. Default value Eth.
format (optional): The format of the token id. Available values : decimal, hex. Default value : decimal.
cursor (optional): The next page of data to retrieve. Next page cursor value returned from each request.
limit(optional): limit (max 100).
address (optional): The owner of a given token (i.e. 0x1a2b3x...). If specified, the user attached to the query is ignored and the address will be used instead.
tokenAddresses(required): Array of contract addresses
Get the NFT transfers. Returns an object with the number of NFT transfers and the array of NFT transfers (asynchronous).
Options:
chain(optional): The blockchain to get data from. Valid values are listed on Supported Chains. Default value Eth.
format (optional): The format of the token id. Available values : decimal, hex. Default value : decimal.
direction(optional): The transfer direction. Available values : both, to, from . Default value : both.
cursor (optional): The next page of data to retrieve. Next page cursor value returned from each request.
limit(optional): limit (max 100).
address (required): A user address (i.e. 0x1a2b3x...). If specified, the user attached to the query is ignored and the authenticated address will be used instead.
// get mainnet NFT transfers for the current userconsttransfersNFT=awaitMoralis.Web3API.account.getNFTTransfers();// get BSC NFT transfers for a given address// with most recent transactions appearing firstconstoptions= { chain:"polygon", address:"0x75e3e9c92162e62000425c98769965a76c2e387a", limit:"5",};consttransfersNFT=awaitMoralis.Web3API.account.getNFTTransfers(options);
import React from"react";import { useMoralisWeb3Api } from"react-moralis";constWeb3Api=useMoralisWeb3Api();constfetchNFTTransfers=async () => {// get mainnet NFT transfers for the current userconsttransfersNFT=awaitWeb3Api.account.getNFTTransfers();console.log(transfersNFT);// get BSC NFT transfers for a given address// with most recent transactions appearing firstconstoptions= { chain:"polygon", address:"0x75e3e9c92162e62000425c98769965a76c2e387a", limit:"5", };constbscTransfersNFT=awaitWeb3Api.account.getNFTTransfers(options);console.log(bscTransfersNFT);};
Gets NFT transfers from a block number to a block number
Options:
Needs at least one of from_block, to_block , from_date , to_date
chain(optional): The blockchain to get data from. Valid values are listed on Supported Chains. Default value Eth.
from_block(optional): The minimum block number from where to get the transfers. Provide the param 'from_block' or 'from_date'. If 'from_date' and 'from_block' are provided, 'from_block' will be used.
to_block (optional): The maximum block number from where to get the transfers. Provide the param 'to_block' or 'to_date', If 'to_date' and 'to_block' are provided, 'to_block' will be used.
from_date (optional): The date from where to get the transfers (any format that is accepted by momentjs). Provide the param 'from_block' or 'from_date'. If 'from_date' and 'from_block' are provided, 'from_block' will be used.
to_date(optional): Get transfers up until this date (any format that is accepted by momentjs). Provide the param 'to_block' or 'to_date'. If 'to_date' and 'to_block' are provided, 'to_block' will be used.
format(optional): The format of the token id. Available values : decimal, hex. Default value : decimal.
Retrieve NFT transfers by block number or block hash. Returns an array of NFT transfers (asynchronous).
Options:
chain(optional): The blockchain to get data from. Valid values are listed on Supported Chains. Default value Eth.
block_number_or_hash (required): The block hash or block number.
constoptions= { chain:"bsc", block_number_or_hash:"11284830" };// get NFT transfers by block number or block hashconstNFTTransfers=awaitMoralis.Web3API.native.getNFTTransfersByBlock( options);
import React from"react";import { useMoralisWeb3Api } from"react-moralis";constWeb3Api=useMoralisWeb3Api();constfetchNFTTransfersByBlock=async () => {// get NFT transfers by block number or block hashconstoptions= { chain:"bsc", block_number_or_hash:"11284830" };constNFTTransfers=awaitWeb3Api.native.getNFTTransfersByBlock(options);console.log(NFTTransfers);};
using MoralisUnity;
using MoralisUnity.Web3Api.Models;
using UnityEngine;
public class Example
{
public async void fetchNFTLowestPrice()
{
Trade NFTLowestPrice = await Moralis.Web3Api.Token.GetNFTLowestPrice(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", ChainList.eth, days: 2);
Debug.Log(NFTLowestPrice.ToJson());
}
}
using MoralisUnity;
using MoralisUnity.Web3Api.Models;
using UnityEngine;
public class Example
{
public async void fetchNFTMetadata()
{
NftContractMetadata metadata = await Moralis.Web3Api.Token.GetNFTMetadata(address: "0x7dE3085b3190B3a787822Ee16F23be010f5F8686", ChainList.eth);
Debug.Log(metadata.ToJson());
}
}
Requests for contract addresses not yet indexed will automatically start the indexing process for that NFT collection
using MoralisUnity;
using MoralisUnity.Web3Api.Models;
using UnityEngine;
public class Example
{
public async void fetchNFTOwners()
{
NftOwnerCollection nftowners = await Moralis.Web3Api.Token.GetNFTOwners(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", ChainList.eth);
Debug.Log(nftowners.ToJson());
}
}
Make sure to include a sort parm on a column like token_id for consistent pagination results
Requests for contract addresses not yet indexed will automatically start the indexing process for that NFT collection
Returns an object with NFT trades for a given contract and marketplace
Options:
chain(optional): The blockchain to get data from. Valid values are listed on Supported Chains. Default value Eth.
from_date (optional): The date from where to get the trades(any format that is accepted by momentjs). Provide the param 'from_block' or 'from_date' If 'from_date' and 'from_block' are provided, 'from_block' will be used.
to_date (optional): Get the trades to this date (any format that is accepted by momentjs). Provide the param 'to_block' or 'to_date' If 'to_date' and 'to_block' are provided, 'to_block' will be used.
from_block (optional): The minimum block number from where to get the tradesProvide the param 'from_block' or 'from_date' If 'from_date' and 'from_block' are provided, 'from_block' will be used.
to_block (optional): The maximum block number from where to get the trades. Provide the param 'to_block' or 'to_date' If 'to_date' and 'to_block' are provided, 'to_block' will be used.
cursor (optional): The next page of data to retrieve. Next page cursor value returned from each request.
limit(optional): limit (max 100).
marketplace (optional): Marketplace from where to get the trades (only opensea is supported at the moment).
address (required): Address of the contract(i.e. 0x1a2b3x...).
using MoralisUnity;
using MoralisUnity.Web3Api.Models;
using UnityEngine;
public class Example
{
public async void fetchNFTTrades()
{
TradeCollection trades = await Moralis.Web3Api.Token.GetNFTTrades(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", ChainList.eth, limit: 10);
Debug.Log(trades.ToJson());
}
}
using MoralisUnity;
using MoralisUnity.Web3Api.Models;
using UnityEngine;
public class Example
{
public async void fetchTokenIdMetadata()
{
Nft tokenIdMetadata = await Moralis.Web3Api.Token.GetTokenIdMetadata(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", tokenId: "1", ChainList.eth);
Debug.Log(tokenIdMetadata.ToJson());
}
}
using MoralisUnity;
using MoralisUnity.Web3Api.Models;
using UnityEngine;
public class Example
{
public async void fetchTokenIdOwners()
{
NftOwnerCollection tokenIdOwners = await Moralis.Web3Api.Token.GetTokenIdOwners(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", tokenId: "1", ChainList.eth);
Debug.Log(tokenIdOwners.ToJson());
}
}
using MoralisUnity;
using MoralisUnity.Web3Api.Models;
using UnityEngine;
public class Example
{
public async void fetchWalletTokenIdTransfers()
{
NftTransferCollection transfers = await Moralis.GetClient().Web3Api.Token.GetWalletTokenIdTransfers(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", tokenId: "1", ChainList.eth);
Debug.Log(transfers.ToJson());
}
}