You may use for the particular era:
const particularEra=1319;
const stakers = await api.query.staking.erasStakers(api.createType('EraIndex', paticularEra), VALIDATOR);
console.log('validator and nominators inside (other):',
JSON.parse(JSON.stringify(stakers)));
Output will be like (where others
are validators):
total: '0x0000000000000000005b9ef09bfade21',
own: 100000000000000,
others: [
{
who: '13yrrdCBQQ9RTy2dVFJ8yC6jQdJs5HqHrZZcVCYxsbJtCc82',
value: 70458858722673
},
...
]
Or for all eras and validators:
const stakers = await api.query.staking.erasStakers.entries();
stakers
.forEach((x) => {
console.log(`Validator: ======================\n\n`,
x[0].toHuman());
console.log(`Nominators:\n\n`,
x[1].others.toJSON());
});
Output will be like ('1,320' is era):
Validator: ======================
[ '1,320', '138X7AdRKX7myWMwoFgWfHj1WUZKKZrKTr2CZ8pGUUXTrkDu' ]
Nominators:
[
{
who: '15qunVeyLEybbNzwhG9Zo4Xz8dtbzc2r58eydd31M3wiz2y3',
value: 1135000000000000
},
...
]
Minor comments:
Spec saids about erasStakers
:
Note: Deprecated since v14. Use `EraInfo` instead to work with exposures.
...
New `Exposure`s are stored in a paged manner in `ErasStakersPaged` instead.
But EraInfo
and erasStakersPaged
still not exists.