0

In order to get the number of validators on a relay chain I query the Staking.ValidatorCount storage which returns an integer.

How do I get the list of all validators and the amount of DOT/KSM bonded by each?

1
  • Do you want to know the amount that they have bonded, or the amount of nomination that they have received and is contributing to them being elected? The below answer is about the former, not the latter.
    – kianenigma
    Commented Jan 28, 2023 at 13:01

1 Answer 1

2

First you have to get the list of validators, and for every one of the list you can get his total balance bonded in Staking:

    const validators = await api.query.session.validators();
    validators.forEach(async (accountId) => {
        const stakingLedger = await api.query.staking.ledger(accountId);
        if(stakingLedger.toHuman()){
            const stakingLedgerObject = JSON.parse(stakingLedger);
            const bonded = stakingLedgerObject.total;
            console.log(`${accountId}: ${bonded}`);
        }
    });

The const stakingLedger here has this information:

    {
      stash: '15apjb1k8NBZNsUr93tcffaGU6Z6erUm8TjSawpTWc8WAaKP',
      total: '10,000,000,000',
      active: '10,000,000,000',
      unlocking: [],
      claimedRewards: [
        '852', '853', '854', '855', '856', '857', '858',
        '859', '860', '861', '862', '863', '864', '865',
        '866', '867', '868', '869', '870', '871', '872',
        '873', '874', '875', '876', '877', '878', '879',
        '880', '881', '882', '883', '884', '885', '886',
        '887', '888', '889', '890', '891', '892', '893',
        '894', '895', '896', '897', '898', '899', '900',
        '901', '902', '903', '904', '905', '906', '907',
        '908', '909', '910', '911', '912', '913', '914',
        '915', '916', '917', '918', '919', '920', '921',
        '922', '923', '924', '925', '926', '927', '928',
        '929', '930', '931', '932', '933', '934'
      ]
    }

But probably you only want the total.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.