Skip to main content
The InitiaJS SDK offers a powerful 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, you’ll explore several examples demonstrating how to leverage these helper functions to retrieve key data points efficiently using the SDK. For demonstration purposes, 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, you can use the balance function from the bank module. This function takes in an address and returns the balance of the account. First, make the necessary imports and initialize the RESTClient.
Adjust gasPrices and gasAdjustment according to current network conditions for optimal transaction processing.
Next, 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 the response from the query is paginated, so you need to handle the pagination properly in the function. Specifically, responses that are paginated will return a next_key in the pagination object, which you can use to get the next page of results. Then keep looping through the results until you have all the pages, which you will know is the case when next_key is null.
You 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

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