?

Interoperable Data Extraction with Ankr’s Advanced API

Galina Mikova

Galina Mikova

January 6, 2023

4 min read

Medium_Post_23_121_437167b8ee.jpg

At Ankr, we run RPC endpoints to multiple blockchains. In aggregate, we serve 100s of billions of requests every month. To make it easier for developers to query blockchains and pull information faster, we've developed Advanced APIs to call RPC methods using libraries in Python, Ruby, JavaScript, and cURL.

One of the Advanced APIs that delivers a host of useful features and functions to developers is the Query API. Query API is an access-ready solution that enables projects to interact with multiple blockchains using a single request. By indexing blockchain data from all eight currently supported chains, searching through large amounts of data is easier and faster than ever before. Query API can boast almost instantaneous processing speeds (due to the key-value filtering supported) for searches that might ordinarily take hours to process.

What is ankr_getLogs Used for?

ankr_getLogs allows you to view events that occurred on the blockchain.

A core part of Web3 or decentralized applications (dApps) is the ability to understand when and what events happen on a blockchain. These events can trigger updates or notifications within the application that are then communicated to users. To allow users to easily access data about these events from outside of the blockchain, AnkrScan keeps an event log on the transactions of every block and node run on Ankr. To be able to read and understand these logs, we use the ankr_getLogs JSON-RPC method.

What are Logs or Events?

Logs and events are used interchangeably—smart contracts generate logs by firing off events, so logs provide insight into smart contract events.

Transaction receipts contain logs.

When a transaction is mined, we can view the event logs for that transaction by calling ankr_getLogs and then acting on the results.

For example, if a purchase is being made using crypto payments, we can use ankr_getLogs to see if the sender successfully made the payment before providing the item purchased.

Why use logs?

One advantage of using event logs is that they are inexpensive in comparison to other EVM functions. This data can be read outside of applications and used to perform an action, such as updating a front-end.

The goal of ankr_getLogs is to make interacting with supported blockchain as fast and easy as possible. Rather than sending separate requests for pulling data on events to access logs, you can group them in a single request to save time.

ankr_getLogs was crucial in achieving faster response times when producing the snapshot after the aBNBc exploit. We had to retrieve information for hundreds of transactions across to and from multiple addresses across different blockchains in a matter of minutes to localize the attack and contain the leaked funds from compromised smart contracts. What would have ordinarily taken 8 hours or more to complete while involving dozens of separate queries to request event and log entries was expedited down to a matter of 10 seconds to 1 minute using Advanced API functionality.

Running ankr_getLogs allowed us to combine these requests into a single call, retrieving information for hundreds or thousands of separate requests for separate events to create one snapshot. And this is just one of the many use cases for Ankr’s Advanced API.

It makes no difference whether you are creating a Web3 project from scratch, an NFT marketplace, or simply want to connect your existing infrastructure to Web3; the ability to pull data from and index blockchains is critical.

On-chain data is at the heart of all Web3 projects and dapps, as the information contained within these blockchains is essential for a good UX.

As a result, you must sync everything from user balances to transaction histories. If you want to build multi-chain dapps, you must use data from multiple blockchains. The ability to do so quickly and efficiently will allow you to create more sophisticated dapps, platforms and protocols that will provide additional value to your customers.

However, from a traditional standpoint, indexing the blockchain has been extremely difficult due to the large amount of time and resources required.

Query ankr_getLogs

You can easily pull data from eight supported blockchain using Ankr’s Advanced API. Running the ankr_getLogs command allows you to detect transactions and events - even in unconfirmed states - in a real-time transaction table.

Using the Query API provides access to on-chain blockchain events and logs without any heavy lifting. ankr_getLogs is also cross-chain compatible meaning you can access data from multiple networks.

Understanding when and what events occurred on a blockchain is a critical component of web3 or decentralized applications. AnkrScan keeps an event log on every block's transactions for all the blockchains we support and the nodes run on Ankr’s RPC so that users can easily access data about these events from outside the blockchain.

Previously, to use the data stored in the blockchain you need to re-index the entire chain, which is a time-intensive task. It is difficult to create an index separately because the blocks are added and removed repeatedly in the process of forming the blockchain itself.

Ankr’s Advanced API not only solves this tedious and time-consuming task, but also provides a way to facilitate general usage; thus, ankr_getLogs becomes an important part of the overall process in order to create a variety of applications.