forked from silentnoname/cosmos-learn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-queryDelegationRewards.js
36 lines (27 loc) · 1004 Bytes
/
1-queryDelegationRewards.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {
QueryClient, setupDistributionExtension
} from "@cosmjs/stargate";
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
async function getQueryClient(rpcEndpoint) {
const tendermint34Client = await Tendermint34Client.connect(rpcEndpoint);
const queryClient = QueryClient.withExtensions(
tendermint34Client,
setupDistributionExtension
);
return queryClient;
}
async function start(address) {
const rpcEndpoint = "https://rpc.cosmos.network";
const queryClient = await getQueryClient(rpcEndpoint);
let rewards = await queryClient.distribution.delegationTotalRewards(address);
let totalRewards = 0;
let validators = [];
for (let reward of rewards.rewards) {
validators.push(reward.validatorAddress);
console.log(reward)
totalRewards += Number(reward.reward[0].amount) / 1e24;
}
console.log("Pending rewards: " + totalRewards);
}
const address = '';//enter cosmos address
start(address);