0

I'm trying to call api.query.authorityDiscovery.keys as is described here from rpc.polkadot.io like:

let current_auth_keys = await api.query.authorityDiscovery.keys();

and I keep getting:

TypeError: Cannot read property 'keys' of undefined

as if api.query does not have authorityDiscovery property/object contrary to what is written in the documentation. Could you tell me what am I getting wrong? I'm using:

"@polkadot/api": "^10.1.4"

1 Answer 1

1

Based on the Polkadot.js API source code you may access the list of keys from the current authority set using the following code:

import { ApiPromise, WsProvider } from '@polkadot/api';

async function main () {
  const wsProvider = new WsProvider('wss://rpc.polkadot.io');
  const api = await ApiPromise.create({ provider: wsProvider });
  let authorities = await api.call.authorityDiscoveryApi.authorities();
  console.log('authorities: ', authorities.toJSON());
}

main().catch(console.error).finally(() => process.exit());

Or just go to https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polkadot.io#/js, paste the following, and click the play icon to view the output on the right.

console.log((await api.call.authorityDiscoveryApi.authorities()).toJSON());

The previously available function api.query.authorityDiscovery appears to have now been removed and replaced with that Runtime call. The documentation is open-source and the Storage section doesn't appear to have been updated yet, but it does include api.call.authorityDiscoveryApi in the Runtime section here. For example, if you go to https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polkadot.io#/runtime, and choose endpoint authorityDiscoveryApi and authorities(), then click button 'Submit Runtime call', it will output the list of keys from the current authority set.

1

Your Answer

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

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