RESTClient
that simplifies the process of querying data from both the Initia L1 and rollups. This client encapsulates various endpoints and methods into user-friendly helper functions, organized under sub-categories of the rest
client based on their corresponding Cosmos SDK modules.
In this tutorial, we’ll explore several examples demonstrating how to leverage these helper functions to retrieve key data points efficiently using the SDK.
For demonstration purposes, we will assume that all of these examples are implemented in a file named src/query.ts
.
Querying Account Balance
To query the balance of an account, we can use thebalance
function from the bank
module. This function takes in an address and returns the balance of the account.
First, we will make the necessary imports and initialize the RESTClient
.
Adjust gasPrices and gasAdjustment according to current network conditions for optimal transaction processing.
next_key
in the pagination object, which we can use to get the next page of results. We will then keep looping through the results until we have all the pages, which we will know is the case when next_key
is null
.
Complete Example
src/query.ts
VM-Agnostic Queries
VM-agnostic queries are queries that can be used across all VMs.balance()
: query the balance of an account
blockInfo()
: query the block information
txInfo()
: query the transaction information
price()
: query the oracle price
VM-Specific Queries
MoveVM
viewfunction()
: query the move contract view functions
viewJSON()
: query the move contract view functions with JSON arguments
resources()
: query the move contract resources
modules()
: query the move contract modules
tableInfo()
: query the move contract table info
WasmVM
contractInfo()
: query the wasm contract info
smartContractState()
: query the wasm smart contract state
EVM
call()
: query the evm contract