How to use the NFTScan NFT API to develop Web3 applications on the Polygon network

Formerly known as Matic Network, Polygon is a scaling solution that provides tools to speed up and reduce the cost and complexity of transactions on blockchain networks. However, the massive activity on its blockchain has brought Ethereum to near-crippling due to growing transmission costs and congested traffic. The main purpose of Polygon’s birth is to help Ethereum solve the congestion problem in the chain, a multi-level platform with a large number of side chains, unblock the main platform in an effective and cost-effective way to expand Ethereum, and provide a simpler framework to build interconnection network.

On the other hand, another major use of Polygon is to improve user experience. Ethereum’s handling fees are very expensive, unaffordable for ordinary users and slow. Polygon’s high performance, low fees and speed can solve common user problems. Polygon’s NFT ecosystem is booming and has become the go-to destination for NFTs from Web2 companies.

According to NFTScan data, as of November 3, a total of 692,876,807 NFT assets, 1,519,857 NFT Collections, 2,472,505,127 transaction records, 81,542,228 interacted wallet addresses, and a total transaction volume of 974,589,451 MATIC have been issued on the Polygon network.

Polygon NFTScan:

How to access NFTScan NFT API

Create NFTScan developer account

Before you start using the NFTScan API, you first need to visit the developer website and create an account. Go to the NFTScan official website and click the NFTScan API “Sign Up” button to register.

After logging in, find your own unique API KAY on the Dashboard and copy it. Visit the API documentation and enter your API KEY into the corresponding location in the API documentation. According to the guidance of the documentation, you can start using the API service. In the API documentation, developers can find a variety of interface modes to choose from and choose the most appropriate interface according to their needs.

In the Dashboard, developers can also view statistics on their own API usage to help record historical usage data. Not only that, NFTScan also provides each registered developer with an API call service of 1M CU, which can be used to request all NFT API interfaces, and the CU will never expire until it is used up!

View Polygon NFT API documentation

After successfully registering a developer account to obtain the API Key, you need to view the NFTScan API documentation. The API documentation contains all API endpoints and parameters that can be used, as well as details on how to construct requests and handle responses. Please read the API documentation carefully and make sure you understand how to use the API to get the data you need. The NFTScan API service is dedicated to helping developers improve the experience of obtaining NFT data analysis.

NFTScan currently has the largest and most comprehensive NFT Collection library on the entire network, supporting Ethereum, Solana, BNBChain, Bitcoin, TON, Polygon, zkSync, Aptos, Linea, Base, Avalanche, Arbitrum, Optimism, Scroll, Fantom, Moonbeam, PlatON, Cronos , Gnosis 19 blockchain full NFT data, covering a wide range of NFT data, providing a complete set of interfaces to obtain ERC721 and ERC1155 assets as well as transaction, project, market statistics and other information, currently supports more than 60 EVM-specific The public interface of the compatible chain, as well as a batch of interfaces of the same model for Solana, Aptos, Bitcoin, and TON, largely meet the needs of developers for indexing multiple types of NFT data.

Polygon NFT API Model

It mainly includes the following three model interfaces, including an overall introduction and description of some core API fields, so that developers can know how to obtain data and use this information to serve the Dapp service they are building.

Assets API: “Assets” is the most critical data field in NFT, used to uniquely identify and describe digital assets. Developers can gain a comprehensive understanding and build related applications by extracting the “Assets” data of NFTs on the Polygon blockchain. The “Assets” object provides the unique identification of digital assets and data throughout its life cycle, providing a basis for developers to understand and apply NFT.

Transactions API: The transaction model represents the full transaction data of an NFT asset on the blockchain, providing developers with the complete life cycle transaction information of the NFT. Including NFT mint, transfer, sale, and other transaction activities, providing developers with the opportunity to gain in-depth understanding of the flow and evolution of NFT assets in the Polygonecosystem. NFTScan continuously aggregates NFT trading markets and related trading contract information from various blockchain networks. Currently, NFTScan has been included to track and understand the dynamics of the NFT market. It also helps developers build NFT-based applications and tools.

Collections API:NFTScan obtains off-chain data such as descriptions, social media and other basic information related to NFT Collections. NFTScan obtains this information through APIs provided by the most mainstream NFT markets in various blockchain networks. In addition, the current floor price information is centralized data based on the order information of the NFT market, which is also available through the API.

Polygon NFT API Retrieval

1/Retrieve Assets Series

  • Get NFTs by account (Retrieve NFTs by wallet address)

  • Get all NFTs by account (retrieve all NFTs from the wallet address and group the NFTs according to the contract address. If the total number of NFTs owned by the account address exceeds 2000, the returned NFTs will be limited to less than 2000. In this case, Developers and users can obtain all NFTs owned by the account address by account through paging query requests)

  • Get minted NFTs by account (retrieve minted NFTs of the wallet address)

  • Get NFTs by contract (retrieve NFTs by contract address and sort by token_id in ascending order)

  • Get single NFT

  • Get multiple NFTs (retrieve NFTs of multiple contract addresses at the same time)

  • Search NFTs (This interface returns a list of NFT assets by applying a search filter in the request body. Assets are sorted by nftscan_id in ascending order)

  • Get NFTs by attributes (This interface returns a set of NFTs belonging to the NFT contract address with attributes, and the NFTs are sorted by token_id in ascending order)

  • Get all multi-chain NFTs by account (This interface returns all multi-chain NFTs owned by the account address, and the NFTs are grouped according to the contract address)

Here we use the Get NFTs by contract interface to

“/v2/assets/{contract_address}”

To retrieve the NFT details under a contract address, the path parameters include contract_address as an option. Here we are querying the NFT under Owlpha .

Click Try it, and the data is returned as follows. The data response result displays the basic data and metadata information of all items in the NFT Collection. Here we have selected Owlpha, and you can see a total of 3333 Items under the project. Return data Sort by token_id, for example, item with id 0:

1) Basic data of a single item:

0x12aa01f646fe5c993c66c9c86eddad4e514f6cbc and the name is Owlpha, the NFT Token id queried here is 0, the proportion in the project is 1, the protocol standard is erc721, the wallet address/holder wallet address at the time of Mint, was minted The timestamp/Mint hash address/Token URI address.

latest_trade_price (last transaction price)/latest_trade_symbol (currency of the last transaction price), latest_trade_timestamp (last transaction timestamp) currently display null, and the returned value is empty, indicating that the item has not been traded.

2) Metadata: From the metadata of the project, we can see that the Metadata data is hosted on ipfs, in the format of image/png, the storage path and the detailed feature description of the image.

3) Rarity description: The score is 0.9080396907866151, and the overall rarity ranking is 2494th. ?

2/ Retrieve Transactions Series

  • Get transactions by account (this interface returns the NFT transaction list of the wallet address)

  • Get transactions by contract (This interface returns the NFT transaction list of the NFT contract address)

  • Get transactions by NFT (this interface returns the NFT transaction list of a single NFT)

  • Search transactions (This interface returns a list of NFT transactions by applying a search filter in the request body)

  • Get transactions by to address (This interface returns a list of NFT transactions filtered by transaction parameters)

  • Get transactions by hash (This interface returns transaction records queried based on the transaction hash list)

Here we pass Get transactions by contract

The interface “/v2/transactions/{contract_address}” retrieves the NFT transaction record of a certain NFT contract address. The query parameter can select the NFT event type of the transaction (Mint/Transfer/Sale/Burn). Use ‘;’ separates multiple events. ?

Likewise here we retrieve Owlpha’s NFT transaction records. According to the event type of Mint, the result response data contains all key data of Mint for all Items under this NFT Collection, such as transaction hash value, From and To addresses, block information, gas consumption, transaction timestamp and other basic data of NFT transactions. characteristic information.

3/ Retrieve Collections Series

  • Get an NFT collection (query details based on the contract address of the Collection, including overview and classification of items according to description, basic summary information such as holder distribution, average price, floor price, etc.)

  • Search NFT collections (This interface returns information for a Collection list sorted by deployment block number in ascending order by applying a search filter in the request body)

  • Get NFT collections by account (This interface returns item list information with a given account address, Collection is sorted from high to low by floor price)

  • Get NFT collections by ranking (This interface returns item list information with a given sorting field, Collection is sorted by the given sorting field and the given sorting direction)

Here we use the interface Get an NFT collection

The search address of “/v2/collections/{contract_address}” is

0x12aa01f646fe5c993c66c9c86eddad4e514f6cbc Details for Owlpha :

4/ Collection Statistics: Collection statistical analysis series

  • Collection Statistics (this interface provides analytical statistical overview data of NFT Collection)

  • Collection Trade Distribution (This interface mainly provides project transaction distribution)

  • Collection Trending Statistics (mainly returns the Trading statistics sorting of an item)

  • Collection Holding Amount Distribution (This interface can return the distribution information of NFT project holdings)

  • Collection Holding Period Distribution (data returns NFT project holding period distribution information)

  • Collection Blue Chip Statistics (blue chip project statistical overview data)

  • Collection Blue Chip List (for a list of blue chip projects involved in this project, please refer to NFTScan Blue Chip Collection)

  • Collection Top Holder (the top holder distribution of the Collection)

Here we use the interface Collection Top Holder

“/v2/statistics/collection/holder/{contract_address}” mainly returns the holding distribution under an NFT Collection. Please refer to NFTScan Holders:

5/ Account Statistics Series

  • Account Overview Statistics (This interface returns the overview statistical information of the account address, please refer to NFTScan Overview)

  • Account Holding Distribution (This interface returns the NFT holding distribution statistics of the account address, refer to NFTScan Portfolio)

  • Account Holding NFT Trending (This interface returns the NFT holdings or quantity statistics of the account address, refer to NFTScan Portfolio)

6/ Analytic Statistics Series

This series of interfaces are usually used to obtain information related to data analysis and statistics on the NFTScan Polygon network, such as Trade Ranking, Mint Amount, etc. These interfaces allow developers or users to query, analyze, and retrieve information related to specific data sets or indicators. Statistical data. It can be used for a variety of purposes, including market analysis, trend tracking, investment decisions, and understanding the nature of specific data.

Reference: https://polygon.nftscan.com/analytics

7/ Refresh Metadata

  • Refresh NFT metadata

  • Refresh NFT metadata by contract

Interfaces such as Refresh Metadata can help developers or users submit background refresh metadata tasks. After review, the task will refresh the submitted specified Item or the entire contract metadata.

8/ Other

  • Get latest block number (returns the latest block number that NFTScan has reached)

  • Get NFT amount by account (returns the amount of ERC721 and ERC1155 NFT owned by the account address based on the search list in the request body)

  • Get NFT owners by contract (returns the owner list of ERC721 NFT contract address, NFT is sorted by token_id in ascending order)

  • Get owners by an NFT (returns a list of owners of an ERC1155 NFT, sorted by account_address in ascending order)

Construct relevant NFT API requests

After developers find the required Polygon API interface and parameters in NFTScan’s API documentation, they can code the API request using the programming language of their choice (such as Python, Java, JavaScript, etc.). The following is an example that demonstrates how to use Python to request transaction records for an NFT contract address. In this example, the contract address we use is

0x12aa01f646fe5c993c66c9c86eddad4e514f6cbc,

And use the NFT interface “/v2/transactions/{contract_address}”?

import requests</code>
<code># Define the API endpoint and contract address</code><code>api_endpoint = "https://api.nftscan.com/v2/transactions/"</code><code>contract_address = "0x12aa01f646fe5c993c66c9c86eddad4e514f6cbc " # Replace with the actual contract address</code>
<code># Make the API request</code><code>response = requests.get(api_endpoint + contract_address)</code>
<code># Check the response status code</code><code>if response.status_code == 200:</code><code> # Parse the JSON data from the API response</code><code> transactions = response .json()</code><code> # Process the transaction records for the NFT contract address...</code><code> for transaction in transactions:</code><code> print("Transaction Hash: ", transaction["hash"])</code><code> print("Block Number:", transaction["blockNumber"])</code><code> # You can add more handling for transaction information...</code><code>else:</code><code> print("API request failed, status code:", response.status_code)</code>

In the above example, we build the API endpoint and contract address, and then use the requests.get method to initiate a GET request to obtain the transaction record of the NFT contract address. If the request is successful, the developer can extract the transaction information from the JSON data of the API response and process it.

About NFTScan

NFTScan was founded in early 2021 and is headquartered in Hong Kong. It is the world’s leading NFT data infrastructure service provider and currently supports Bitcoin, Ethereum, BNBChain, Polygon, Solana, TON, Arbitrum, Optimism, zkSync, Base, Scroll, Aptos 19 mainstream blockchain networks including. The NFTScan team is committed to providing simple and efficient NFT retrieval services to hundreds of millions of Web3 users, providing safe and stable multi-chain NFT indexing services to the new generation of financial technology companies, and using data to promote the prosperity and development of the NFT ecosystem! Currently, NFTScan is providing multi-chain NFT API data services to 5000+ developers including MetaMask, CMC, Binance NFT, Bybit, KuCoin, HashKey Group, Mask, imToken, Enjin, Coin98, etc.!