Querying Hashgraph Data on Arkhia using Hedera’s JSON RPC — Arkhitect Awareness Series

Arkhia
4 min readOct 19, 2022

--

Using Arkhia & the JSON-RPC to Manage Mirror Nodes

Welcome back to another post in the Arkhitect Awareness Series. In this article, you’ll learn how to leverage Arkhia to efficiently call transaction data from the Hedera network using the JSON RPC. Arkhia is a performant middleware solution for Hedera developers looking to ensure timely, accurate data for their dApps’ mission-critical services.

If you are not already registered on Arkhia, visit the “Getting Started” section and follow the simple steps to sign up and get a walkthrough of the dashboard. If this is your first time hearing about Arkhia, we suggest you start with our introductory blog. Otherwise, let’s get started.

Understanding the JSON-RPC

Per the Hedera docs — The Hedera JSON RPC Relay is an open-source project that implements the Ethereum JSON-RPC standard. This allows developers to interact with Hedera nodes using familiar Ethereum tools. For Ethereum developers and users, it simplifies the process of deploying, querying, and executing smart contracts on Hedera.

On Arkhia, users can utilise the JSON-RPC to retrieve data of various queries on both mainnet and testnet.

When using the REST API, you use a standard set of URLs with variations specific to your query. When querying transaction history, you can filter by account, balance, transaction type, topic, token, NFT, smart contract, and more.

How to make RESTful queries on Arkhia

Potential users are encouraged to create an Arkhia account to get the endpoint URLs needed to make queries. Trial Arkhia through a free account and upgrade later!

Specific queries can be found here. Use the header key ‘x-api-key’ with your API token for authenticated access from your Arkhia Dashboard.

Example Queries on Arkhia Using JSON-RPC

If you already have experience working with the JSON-RPC endpoints on EVM-based protocols, you will find that setting up a provider object with the relay is an identical process. We have included a brief code snippet to illustrate this below. If you do not have experience linking applications to Web3 services, read on. All samples are based around the Javascript Web3 library.

Setting up your Provider

In order to access the Web3 (or Ethers) functions, you must first set up an object which allows for HTTP connections to the JSON-RPC. This object is instantiated with the connection string provided to you on the Arkhia dashboard. This code block shows the creation of a provider object:

Here you can see that the provider is created with various options allowing for configuration of network access, CORs, timeouts, credentials, etc. This is the web3 object that wraps the RPC endpoints defined here. Note that due to both protocol differences and the early state of the JSON-RPC relay, some API functions will not work yet.

Checking the Status of your Connection

Given the wide array of connections and dependencies when integrating into decentralised technologies, checking the quality and status of any connections is important. You can do this easily with this function:

This is using the `net` API built into Web3, so note that some endpoints in Web3 are wrapping the JSON-RPC itself, and some are utils that may have a different relationship with the provider. Check the documentation linked in the earlier sections of this article to acclimate yourself to the nuances in the library and how it may interact with the Besu EVM implementation found on Hedera.

Querying the Chain

When querying information from the chain, you can use either Promises or Async/Await to consume data from the DLT. We have listed a few tests you can run yourself below:

Here we are simply querying the net/chain/web3 API’s that would usually be found on the nodes themselves. For querying contracts, view this documentation here. Keep in mind that some contract functionalities and fees will differ from what you may be used to working with EVM chains.

Conclusion

We hope this blog has helped you learn how to utilise Arkhia to query various types of transactions on the Hedera network. If you do not already subscribe to Arkhia and its suite of services, visit Arkhia.io to learn about the various benefits it brings to builders on Hedera. We look forward to providing you with reliable, high-quality data while you work to empower Web3.

About Arkhia

Arkhia is an enterprise-grade Infrastructure-as-a-Service (IaaS) provider for decentralised technologies. We are empowering organisations, teams and individuals to build fast, modular and scalable solutions in our high availability environments for Web3 applications. Purposely built for reliability, resilience and high throughput, the Arkhia API suite benefits anyone needing ultra reliable network uptime for mission critical applications. To learn more on how we provide enterprise-grade infrastructure, visit arkhia.io, subscribe to our newsletter and follow us on Twitter (@arkhia.io) and LinkedIn.

--

--

Arkhia

Arkhia is a Infrastructure-as-a-Service (IaaS) and Web3 backend provider for blockchain & distributed-ledger developers. Now live!