0

As a developer,I want to use the interface to search this information: which can get the validator detail information like the count of nominators and the commission and others information,

1 Answer 1

1

Everything that can be read onchain is listed here.

For example, to read the commission:

console.log((await api.query.staking.validators("11uMPbeaEDJhUxzU4ZfWW9VQEsryP9XqFcNRfPdYda6aFWJ")).commission)

Which is a Perbill, fixed point parts per billion, and 11uMPbeaEDJhUxzU4ZfWW9VQEsryP9XqFcNRfPdYda6aFWJ is a totally arbitrary validator of Polkadot today.

You can directly paste this into https://polkadot.js.org/apps/#/js.

To get the count of active nominator who end up backing a validator in era:

const lastEra = (await api.query.staking.currentEra()).unwrap();
const exposures = await api.query.staking.erasStakers(lastEra, "11uMPbeaEDJhUxzU4ZfWW9VQEsryP9XqFcNRfPdYda6aFWJ");
console.log(exposures.others.length)

To get the list of all the nominators who casted a vote for 11uMPbeaEDJhUxzU4ZfWW9VQEsryP9XqFcNRfPdYda6aFWJ, you have to iterate the nominators map, but I will leave that up to you to figure out.

3
  • why i search the exposures.others.length not same as the expore show ? exposures.others.length=302 but the the expore show 342
    – Rose
    Commented Oct 3, 2022 at 13:53
  • should i use currentEra or activeEra?
    – Rose
    Commented Oct 3, 2022 at 15:14
  • I think it is best if you ask the difference between currentEra and activeEra in a new question and we will answer it there.
    – kianenigma
    Commented Oct 4, 2022 at 7:09

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.