Skip to content

02QueryingChainDistribution

Ivan Angelkoski edited this page Jun 12, 2023 · 4 revisions

⚠️ The Docs have been moved to https://docs.ts.injective.network/querying/querying-chain/querying-chain-distribution ⚠️

Example code snippets to query data related to delegating to validators from the chain.

Using gRPC

  • Get parameters such as the base and bonus proposer reward
import { ChainGrpcDistributionApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const chainGrpcDistributionApi = new ChainGrpcDistributionApi(endpoints.grpc);

const moduleParams = await chainGrpcDistributionApi.fetchModuleParams();

console.log(moduleParams);
  • Get the amount and denom of rewards for a delegator delagating to a specific validator
import { ChainGrpcDistributionApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const chainGrpcDistributionApi = new ChainGrpcDistributionApi(endpoints.grpc);

const delegatorAddress = "inj...";
const validatorAddress = "injvaloper...";

const delegatorRewardsFromValidator =
  await chainGrpcDistributionApi.fetchDelegatorRewardsForValidatorNoThrow({
    delegatorAddress,
    validatorAddress,
  });

console.log(delegatorRewardsFromValidator);
  • Get the amount and denom of all rewards for a delegator
import { ChainGrpcDistributionApi } from "@injectivelabs/sdk-ts";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";

const endpoints = getNetworkEndpoints(Network.TestnetK8s);
const chainGrpcDistributionApi = new ChainGrpcDistributionApi(endpoints.grpc);

const delegatorAddress = "inj...";

const totalDelegatorRewards =
  await chainGrpcDistributionApi.fetchDelegatorRewardsNoThrow(delegatorAddress);

console.log(totalDelegatorRewards);

⚠️ DOCUMENTATION ⚠️

Clone this wiki locally