Scalability is one of the biggest concerns for the crypto landscape right now. While Ethereum has served as the ideal playground for the growth of dApps in recent times, it has experienced huge setbacks. Network congestion and high transaction costs have been plaguing the Ethereum blockchain, thereby calling for solutions like Polygon

The impressive claims regarding Polygon transaction speed have sparked massive interest in the crypto and blockchain community. Apparently, Polygon can process around 65,000 transactions per second in comparison to Ethereum, which can process around 17 transactions per second. 

As one of the most popular scaling solutions, Polygon has enabled faster validation of transactions alongside lowering costs. However, developers have to encounter the formidable challenge of processing and managing humongous volumes of blockchain data. Therefore, historical data on Polygon is an obvious priority for developers. The following post reflects on the different implications associated with retrieving historical data about Polygon transactions with an outline of the best practices.

Excited to develop a comprehensive understanding of Polygon? Enroll now in Polygon Fundamentals Course

Why Do You Need Historical Data on Polygon?

The ability of Polygon to process multiple transactions at a faster speed also creates a setback for developers. Subsequently, the amount of data they have to manage increases, and developers have to rely on traditional methods. The traditional methods involved spinning up new nodes, carrying out indexing, and managing the nodes for developing databases. 

As a result, developers have to compromise on speed irrespective of the claims regarding Polygon transactions per second, as the process of managing nodes would be expensive and time-consuming. Therefore, the features of Polygon are ultimately restricted whether it has been deployed as a layer 1 or layer 2 solution

How Can You Retrieve Historical Transactions?

The need to retrieve historical transactions on Polygon is clearly evident for addressing the setbacks in Polygon’s performance. You can understand the efforts required for the complicated traditional methods for integrating queries for historical transactions into decentralized applications. 

However, you can find the answers in tools such as Alchemy Transfers API, available on Polygon itself. Interestingly, the API can help in obtaining the details of Polygon transactions with a single request. The API can help you find every detail of the transactions, beginning from their inception.

Build your identity as a certified blockchain expert with 101 Blockchains’ Blockchain Certifications designed to provide enhanced career prospects.

Types of Transactions on Polygon

The search for methods to figure out details of transactions on Polygon would be incomplete without an overview of different types of transactions. Here is an outline of the most common types of transactions you can find on Polygon. 

  • External Polygon Transactions

The external MATIC token transfers are one of the most high-end transactions on Polygon. One of the primary highlights of external MATIC transfers is the external or user-created address serving as the “from” address. The external addresses are associated with private keys and offer flexible accessibility for users. On the other hand, you must notice that Alchemy Transfers API on Polygon does not support external transfers currently. 

  • Token Transactions

The list of Polygon transactions per day also includes token transactions. Token transfers can include non-fungible tokens (ERC-721) or fungible tokens (ERC-20). On top of it, token transactions can also include event logs for transactions with ERC-1155 tokens, which are hybrid non-fungible and fungible tokens

  • Internal ETH Transactions

The types of transactions on Polygon also include internal ETH transfers. You can identify such transactions by checking the “fromAddress,” which must be an internal address or a smart contract address. Think of it as a smart contract calling an external address or another smart contract. However, the Alchemy Transfers API on Polygon does not support internal transfers.

Excited to learn the basic and advanced concepts of ethereum technology? Enroll Now in Ethereum Technology Course

How Can You Use Alchemy Transfers API for Retrieving Historical Data?

The Transfers API is a reliable choice for estimating the average Polygon transaction speed with simple best practices. However, you would need some critical information to narrow down your search. The best way to obtain the information would be to format the request in the form of a JSON object. Here is an example of a JSON object suitable for retrieving data about an ERC-20 transfer.

{

   "jsonrpc":"2.0",

   "id":0,

   "method":"alchemy_getAssetTransfers",

   "params":[

      {

         "fromBlock":"from_Block",

         "toBlock":"to_Block",

         "fromAddress":"FROM_ADDRESS",

         "toAddress":"TO_ADDRESS",

         "contractAddresses":[

            "USDT_ADDRESS"

         ],

         "category":[

            "erc20"

         ]

      }

   ]

})

Key Details of Transactions 

The JSON object would provide you with important details about the concerned Polygon transactions, such as the following.

  • To Block and From Block

The details of the key information about transactions can help in using the Transfers API effectively. Developers can reduce the JSON response time of the API through the configuration of the beginning and final block numbers you want to search. For example, if a transaction happens in a specific block 23876472, then it is important to configure the search. 

Developers can add a small buffer for the concerned block number, and it is important to note that the JSON object only supports hexadecimal strings as inputs for “block number.” In the case of this example, you can try setting the “fromBlock” as 23876470 and the “toBlock” as 23876474. You can enter the input for “fromBlock” as 0x16C5376 and the “toBlock” as 0x16C537A.

  • To and From Address

The next key piece of information about historical transactions on Polygon refers to the “To” and “From” addresses of transactions. It doesn’t take much to guess that both of them represent the destination where the transaction went and its source. 

  • Contract Address

The final and most important piece of information required for the JSON query object is the contract address. You can specify the type of contract associated with the token and whose information you want to find. As mentioned already, Transfers API supports event logs for ERC-721, ERC-20, and ERC-1155 tokens. 

Once you have all these details, you can utilize the Composer tool on Alchemy to return the required results pertaining to the concerned transactions. The simple interface of Alchemy Composer allows users to configure their requests. The Composer tool allows flexibility for specifying details such as the chain and network for streamlining the search. 

In addition, Alchemy Composer also helps in finding comprehensive details regarding Polygon transactions per day with a massive collection of methods. You can leverage the methods for figuring out comprehensive details about desired transactions right from the beginning.

Excited to know more about the fundamentals of Ethereum Development? Enroll in Ethereum Development Fundamentals Course

How to Find Polygon Transaction Details by Using Python?         

Developers can also use Python to query for details of transactions on Polygon. You can use the Alchemy Transfers API on Python for determining historical data of transactions on Polygon, albeit with the need for coding. Here are the simple steps you can follow to figure out historical data related to transactions on Polygon. 

  • Import Statements

One of the first things you need to use Alchemy Transfers API on Python to find Polygon transactions per second, refer to import statements. The import statements are crucial requirements for importing the modules that you would have to use later. Here are the commands you can enter for import statements.

import json

from web3 import web3

import requests

In case you don’t have the ‘web3’ and ‘requests’ modules in the Python environment, you have to install them. Interestingly, pip commands can come to your rescue in such cases.

pip install web3

pip install requests
  • Alchemy Key

The next step in using Alchemy Transfers API on Python would refer to the use of Alchemy Key. Users must create an Alchemy account to receive their Alchemy Key. Developers have to replace the “ALCHEMY KEY” section with the private API key for the search process.

ALCHEMY_KEY = “ALCHEMY KEY”

w3 = Web3(Web3.HTTPProvider('https://polygon-mainnet.alchemyapi.io/v2/'+ALCHEMY_KEY))

Get familiar with the terms related to Web 3.0 with Web 3.0 Flashcards

  • Configuration of Web3.py

Now, the process to find historical details like Polygon transaction speed through coding on Python would also involve the configuration of Web3.py. Assume that you are trying to find information about an ERC-20 contract. In such cases, you must introduce an additional code over what you would generally use in web3 for correct interactions with the contract. 

Developers must also ensure the use of ERC-20 ABI in the code for proper review of the ERC-20 contract. It is important to note that the contract ABI or the Application Binary Interface serves as the standard approach for interacting with different types of contracts in the world of Ethereum

ERC20_ABI = json.loads('[{"constant":true,"inputs":[],"name":"name","outputs"......{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Approval","type":"event"}]')  
  • Establish the Variables

The method for using Alchemy Transfers API on Python to find the historical details of Polygon transactions is incomplete without setting the variables. You must set the variables so that they refer to the right block numbers and addresses. On top of it, you can also rely on the “w3.eth.contract” method for better flexibility in reading data through the ERC-20 contract.

USDT_ADDRESS = '0xc2132D05D31c914a87C6611C10748AEb04B58e8F'

FROM_ADDRESS = '0x5350E1068f0E138ff306990B16fA4910d970c692'

TO_ADDRESS = '0x9d2b758E3ffd2569c6956676fAE7f8B71A53Ffb5'

from_Block = '0x16C5376'

to_Block = '0x16C537A'

usdt = w3.eth.contract(address=USDT_ADDRESS, abi=ERC20_ABI)
  • Specifying the Query Details

You have to post the information request to the Transfers API. In this step, you have to focus on the “alchemy_getAssetTransfers” method in the request code. In addition, the previously embedded parameters in the JSON query object. It is also important to note the significance of processing the JSON result followed by parsing it to obtain the precise value of tokens transferred in the concerned transaction specified in the query. 

transfer_json = requests.post('https://polygon-mainnet.g.alchemy.com/v2/'+ALCHEMY_KEY, 

json={"jsonrpc": "2.0","id": 0,"method": 

"alchemy_getAssetTransfers","params": 

[{"fromBlock": from_Block,"toBlock": 

to_Block,"fromAddress": FROM_ADDRESS,"toAddress": TO_ADDRESS,"contractAddresses": [USDT_ADDRESS],"category": ["erc20"]}]})

json_response = transfer_json.json()

transfer_val = (json_response['result']['transfers'][0]['rawContract']['value'])
  • Unit Conversion

The final step in using Alchemy Transfers API on Python to obtain transaction details on Polygon would involve unit conversion. It is a critical step in exploring historical transactions on Polygon as unit conversion helps in ensuring better readability. Once you have received and parsed the value of token transaction with the JSON response, you have to implement unit conversion. First of all, it is important to transform the hexadecimal string format into a decimal format before starting the process of unit conversion. 

# convert hexadecimal make to decimal format 

val = (int(transfer_val, 16))

print("USDT TRANSFERED:")

print("--> FROM: " + FROM_ADDRESS)

print("--> TO: " + TO_ADDRESS)

# unit conversion!

print(val/1000000)

Certified web3 professional

Benefits of Alchemy Transfers API

The best thing about Alchemy Transfers API in retrieving details such as Polygon transaction speed is the ease of use. It can help in querying for Polygon transaction details without any complicated settings by using a simple JSON object. On top of it, Alchemy also offers a flexible and easy-to-use Alchemy Composer tool with multiple methods to obtain transaction details. As a result, users can find the transaction details they want by specifying some key pieces of information. In addition, you also have the flexibility of using coding through Python for retrieving information about transactions on Polygon. 

The advantages of Alchemy Transfers API can help in integrating queries for historical transactions on Polygon decentralized applications. As a result, it can help in providing better transparency and insights into the history of token transfers and wallet activity. Subsequently, it can help in developing a user-friendly UI for the Polygon dApps, with the facility for in-depth on-chain analytics. 

How to Retrieve Historical Tick Data on Polygon?

Polygon also offers a REST API interface for retrieving historical tick data. You can use the following request in the interface for obtaining historical quotes on Polygon.

/v2/ticks/stocks/nbbo/{ticker}/{date}

The server allows maximum submission of 50,000 records for individual requests, and it might seem like a huge deal. However, it is only a fraction of the daily tick data volume. Furthermore, you must also notice the importance of including the basic date as well as ticker parameters in the URL. 

The search for historical tick data is different than determining the Polygon transaction speed as it dives way beyond the historical stock data. However, some important HTTP GET parameters can help in the process of retrieving important historical data. Here is an outline of the crucial parameters you need for obtaining historical tick data on Polygon. 

  • Timestamp

The “timestamp” parameter is a long value and serves as a representative of the initial epoch timestamp for the concerned data. You would find the value of the “timestamp” parameter in the range of nanoseconds. 

  • Timestamp Limit

The “timestampLimit” parameter is also a long value and serves as the representative of the ending epoch timestamp. It is also measured in nanoseconds. However, it depends on the condition that the hard limit or custom limit of 50,000 has not been achieved. 

  • Limit

The “limit” parameter is an integer value and specifies the maximum number of records you have to retrieve. The parameter would assume the value as 50,000 if there is no specified value.

  • API Key

The “apiKey” parameter is a string denoting the API key, which is an integral requirement in almost every request.

Excited to develop a comprehensive understanding of Polygon web3 development? Enroll Now in Polygon Web3 Development Course!

Final Words

The methods for retrieving details about historical transactions on Polygon show that simple and effective methods can help you find your way. First of all, it is important to notice the necessity of retrieving historical data about transactions for developers. The radical processing speed of Polygon would obviously cause faster expansion of databases which need efficient management. 

In such cases, simple and effective methods for retrieving historical data about Polygon transactions can serve many prolific outcomes. You can use the Alchemy Transfers API or the REST API interface on Polygon as the recommended tools for finding transaction data. Alchemy Transfers API presents a flexible way to find out the details of specific transactions, especially with the Alchemy Composer tool. 

The ease of access to transaction data could simplify the work of developers in managing dApps. At the same time, historical queries could also offer a better user interface with the opportunity for adding analytics functionalities in dApps. Learn more about Polygon and how it would serve an integral role in the future of web3.

Unlock your career with 101 Blockchains' Learning Programs

*Disclaimer: The article should not be taken as, and is not intended to provide any investment advice. Claims made in this article do not constitute investment advice and should not be taken as such. 101 Blockchains shall not be responsible for any loss sustained by any person who relies on this article. Do your own research!