Querying Data
The InitiaJS SDK offers a powerful LCDClient
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 lcd
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 the balance
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 LCDClient
.
Next, we will create a function to query the balance of an account. This function will take in an address and return the balance of the account.
Note that response from the query is paginated, so we need to handle the pagination properly in the function. Specifically, response that are paginated will return a 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
.
We can then call the function with an address to query the balance of the account.
If successful, you should see an output similar to the following:
Complete Example
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
Was this page helpful?