01QueryingAPI - InjectiveLabs/injective-ts Wiki

Using gRPC

Querying the Accounts Module

Example code snippets to query the accounts module on the API using the gRPC protocol.

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

const endpoints = getEndpointsForNetwork(Network.TestnetK8s);
const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.sentryGrpcApi)

const subaccountLists = await indexerGrpcAccountApi.fetchSubaccountsList(
  injectiveAddress
);

console.log(subaccountLists);
  • Fetching trading account's balances
import { IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts'
import { getEndpointsForNetwork, Network } from "@injectivelabs/networks";

const endpoints = getEndpointsForNetwork(Network.TestnetK8s);
const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.sentryGrpcApi)

const [subaccountId] = await indexerGrpcAccountApi.fetchSubaccountsList(
  injectiveAddress
);
const balances = await indexerGrpcAccountApi.fetchSubaccountBalancesList(
  subaccount
);

console.log(balances);

Query the Explorer Module

Example code snippets to query the explorer module on the API using the gRPC protocol.

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

const endpoints = getEndpointsForNetwork(Network.TestnetK8s);
const network = getNetworkInfo(Network.TestnetK8s);
const indexerGrpcExplorerApi = new IndexerGrpcExplorerApi(endpoints.sentryGrpcApi)

const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const limit = 10

const txs = await indexerGrpcExplorerApi.fetchAccountTransactions({
  address,
  limit,
});

console.log(txs);

Using HTTP REST

Query the Explorer Module

Example code snippets to query the explorer module on the API using the REST protocol.

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

const endpoints = getEndpointsForNetwork(Network.TestnetK8s);
const network = getNetworkInfo(Network.TestnetK8s);
const indexerRestExplorerApi = new IndexerRestExplorerApi(endpoints.sentryHttpApi)

const injectiveAddress = 'inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku'
const limit = 10

const txs = await indexerRestExplorerApi.fetchAccountTransactions({
  address,
  limit,
});

console.log(txs);