Skip to content

02QueryingChain

Bojan Angjelkoski edited this page Nov 6, 2022 · 8 revisions

Using gRPC

Querying the Bank Module

Example code snippets to query the bank module on the chain using the gRPC protocol.

  • Fetching address's balances
import { ChainGrpcBankApi } from '@injectivelabs/sdk-ts'
import { getEndpointsForNetwork, Network } from "@injectivelabs/networks";

const endpoints = getEndpointsForNetwork(Network.TestnetK8s);
const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const chainGrpcBankApi = new ChainGrpcBankApi(endpoints.sentryGrpcApi)

const balances = await chainGrpcBankApi.fetchBalances(injectiveAddress)

console.log(balances)

Using HTTP REST

Example code snippets to query the bank module on the chain using the REST protocol.

  • Fetching address's balances
import { ChainRestBankApi } from '@injectivelabs/sdk-ts'
import { getEndpointsForNetwork, Network } from "@injectivelabs/networks";

const endpoints = getEndpointsForNetwork(Network.TestnetK8s);
const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const chainRestBankApi = new ChainRestBankApi(endpoints.sentryHttpApi)

const balances = await chainGrpcBankApi.fetchBalances(injectiveAddress)

console.log(balances)

⚠️ DOCUMENTATION ⚠️

Clone this wiki locally