-
Notifications
You must be signed in to change notification settings - Fork 196
02QueryingChainBank
Bojan Angjelkoski edited this page Apr 2, 2023
·
5 revisions
Example code snippets to query the chain for bank module related data.
- Get bank module params
import { ChainGrpcBankApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
const endpoints = getNetworkEndpoints(Network.TestnetK8s)
const chainGrpcBankApi = new ChainGrpcBankApi(endpoints.grpc)
const moduleParams = await chainGrpcBankApi.fetchModuleParams()
console.log(moduleParams)
- Fetching injective address's balances
import { ChainGrpcBankApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
const endpoints = getNetworkEndpoints(Network.TestnetK8s)
const chainGrpcBankApi = new ChainGrpcBankApi(endpoints.grpc)
const injectiveAddress = 'inj...'
const balances = await chainGrpcBankApi.fetchBalances(injectiveAddress)
console.log(balances)
- Fetching cosmos address' balances per base denom
import { ChainGrpcBankApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
const endpoints = getNetworkEndpoints(Network.TestnetK8s)
const chainGrpcBankApi = new ChainGrpcBankApi(endpoints.grpc)
const cosmosAddress = 'cosmos...' /* example is using Cosmos Hub */
const denom = 'uatom'
const balance = await chainGrpcBankApi.fetchBalance({
accountAddress: cosmosAddress,
denom
})
console.log(balance)
- Fetching total supply on chain
import { PaginationOption, ChainGrpcBankApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
const endpoints = getNetworkEndpoints(Network.TestnetK8s)
const chainGrpcBankApi = new ChainGrpcBankApi(endpoints.grpc)
const pagination = {...} as PaginationOption
const totalSupply = await chainGrpcBankApi.fetchTotalSupply(
pagination /* optional pagination parameter */
)
console.log(totalSupply)
- Fetching address's balances
import { ChainRestBankApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
const endpoints = getNetworkEndpoints(Network.TestnetK8s)
const chainRestBankApi = new ChainRestBankApi(endpoints.rest)
const injectiveAddress = 'inj...'
const balances = await chainGrpcBankApi.fetchBalances(injectiveAddress)
console.log(balances)
- Fetching cosmos address' balances per base denom
import { ChainRestBankApi } from '@injectivelabs/sdk-ts'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
const endpoints = getNetworkEndpoints(Network.TestnetK8s)
const chainRestBankApi = new ChainRestBankApi(endpoints.rest)
const cosmosAddress = 'cosmos...' /* example is using Cosmos Hub */
const denom = 'uatom'
const balance = await chainGrpcBankApi.fetchBalance(cosmosAddress, denom)
console.log(balance)
Powering the future of decentralized finance.