DEV Community

Cover image for Guide: How to Retrieve Data by NFT Contract Address via NFTScan API?
NFT Research
NFT Research

Posted on

Guide: How to Retrieve Data by NFT Contract Address via NFTScan API?

As the NFT market continues to expand, numerous NFT projects are emerging at an astonishing rate. Investors and developers often find it challenging to gather comprehensive data on these projects. Extracting and processing large amounts of data from blockchains can be time-consuming and daunting. The lack of comprehensive information support hinders the ability to make informed decisions about NFT projects, limiting the development of NFT data applications. Effectively discovering value in a massive and complex dataset is a pressing challenge.

According to NFTScan Multichain data, as of October 13, 2023, NFTScan has provided support for 18 major blockchain networks, generating the following statistics: Over 3 million NFT contracts, more than 1.25 billion NFT assets, 400 million on-chain records, total NFT asset value of $15,609,768,860, and a cumulative NFT transaction volume of $93,122,604,064.

Image description
Source: NFTScan Multichain

With the NFTScan API, developers can efficiently and automatically retrieve and process vast amounts of NFT data without manual intervention, significantly reducing development costs.

Compared to the development of in-house monitoring systems, building directly using NFTScan’s standardized API eliminates the complexities of design and development processes, while also reducing maintenance and upgrade costs. The API enables easy high-frequency monitoring, reducing human labor costs.

Additionally, NFTScan API returns data in a standardized format, making it easier to develop and optimize monitoring tools, and customizable parameter settings allow developers to tailor their solutions.

How to Access NFTScan NFT API:
Step 1: Create a Developer Account

Before using the NFTScan API, you need to visit the developer website and create an account. Visit the official NFTScan website and click the “Sign Up” button for NFTScan API registration: Link to Sign Up.

Image description
NFTScan Developer Platform

After logging in, locate your unique API KEY on the Dashboard. Visit the API documentation and enter your API KEY in the appropriate location according to the documentation’s instructions to start using the API service. In the Dashboard, developers can also view statistics on their API usage to track historical usage data. NFTScan provides 1 million CU of API calls to each registered developer for all NFT API interfaces, and these CUs never expire.

Step 2: Review the API Documentation

After successfully registering your developer account and obtaining an API Key, you need to review the NFTScan API documentation. The API documentation includes all available API endpoints and parameters, along with detailed information on how to construct requests and handle responses. Read the API documentation carefully and ensure you understand how to use the API to retrieve the data you need.

NFTScan currently boasts the most extensive and comprehensive NFT collection database across the entire network. It offers full data support for NFTs from 18 prominent blockchain networks, including Ethereum, Solana, BNBChain, Bitcoin, TON, Polygon, zkSync, Aptos, Linea, Base, Avalanche, Arbitrum, Optimism, Fantom, Moonbeam, PlatON, Cronos, Gnosis, and many more. This extensive coverage includes a wide variety of NFT data, providing a comprehensive suite of interfaces to access ERC721 and ERC1155 assets, as well as transaction, project, and market statistics. NFTScan now supports over 50 public interfaces tailored for EVM-compatible chains, and it offers a set of similar models for Solana, Aptos, and Bitcoin. These services substantially cater to developers’ needs for indexing diverse types of NFT data.

Image description

Step 3: Choose API Endpoints for Retrieving Data by NFT Contract

1. Get NFTs by contract: /v2/assets/{contract_address}

This interface mainly returns a group of NFTs under a contract address. Developers only need to select any ERC-721 or ERC-1155 standard NFT project contract address to obtain complete data for all NFT assets in that project. Query parameters can be selected, such as latest_trade_price, latest_trade_time, and rarity_rank (only applicable to ERC-721 protocol).

Image description

Click “Try it” to view the first returned data.

The contract address is 0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d. The contract is named BoredApeYachtClub, with a token ID of 7856. The protocol standard is ERC721. This data includes the minting address, owner’s address, metadata in JSON format, and much more.

Image description

2. Get transactions by contract: /v2/transactions/{contract_address

This interface allows developers to input any NFT project contract address to get the historical transaction information for the project. Developers can skip the cumbersome process of parsing raw on-chain transactions and directly obtain clean, structured transaction data. Query parameters can include NFT event types (Mint/Transfer/Sale/Burn), separated by ‘;’.

Image description

Here, we have selected the event type “Mint.” After entering your API key, the response data includes all the essential details of this NFT transaction. This information encompasses the transaction hash, block details, “From” and “To” addresses, contract address, transaction timestamp, and other fundamental data. Additionally, it includes characteristics of the NFT transaction, such as the Token ID, transaction amount, and currency.

Image description

3. Get NFT owners by contract: /v2/asset/collection/amount

This interface mainly returns a list of holders for NFT contract addresses under the ERC-721 protocol. Developers only need to input the project’s contract address, and the interface will return an array of address objects, each containing wallet addresses and their corresponding NFT token_ids.

Image description

4. Refresh NFT metadata by contract: /v2/refresh/metadata/contract

This interface allows developers or users to submit backend metadata refresh tasks, which will be reviewed and then refresh the metadata for the entire contract.

Image description

Step 4: Step Building NFT API Requests

In practice, developers can use various programming languages to write code that calls NFTScan APIs, such as Python, Java, JavaScript, and more. For example, in Python, you can utilize the “requests” library to initiate API requests. In JavaScript, you can employ “axios,” while in Java, libraries like “OkHttp” or “Retrofit” can be useful.

When writing the code, developers only need to organize the API parameters, such as the contract address and API key. Subsequently, they can invoke the corresponding NFTScan API to easily obtain standardized JSON-format data.

Here is an example using Python to request historical transaction data for an NFT contract address through NFTScan. This process can be broken down into the following steps:

1. Import Necessary Libraries

First, import the “requests” library in Python, which will be used for making HTTP requests and handling responses.

Image description

2. Build the API request

Define the basic URL of NFTScan’s API and specify the contract address you want to query.

Image description

3. Construct the complete API request URL

Add the contract address to the basic URL to form a complete API request URL.

Image description

4. Make a GET request

Use the “requests” library to make a GET request and check the HTTP response status code. A status code of 200 indicates a successful request.

Image description

5. Process the returned data

If the request is successful, parse the JSON response and handle the historical transaction data. Here’s an example code for processing historical transaction data:

Image description

The provided steps are a basic example of how to use Python to initiate a “Get transactions by contract” API request with NFTScan. Please note that actual code may require additional error handling and data analysis, depending on the developer’s specific needs.

About NFTScan

NFTScan is the world’s largest NFT data infrastructure, including a professional NFT explorer and NFT developer platform, supporting the complete amount of NFT data for 17 blockchains including Ethereum, Solana, BNBChain, Arbitrum, Optimism, and other major networks, providing NFT API for developers on various blockchains.

Official Links:
NFTScan: https://nftscan.com
Developer: https://developer.nftscan.com
Twitter: https://twitter.com/nftscan_com
Discord: https://discord.gg/nftscan

Top comments (0)