1

I want to write a sanity check that my node has the right session keys configured, based on the stash address:

  let nextKeys = await api.query.session.nextKeys(stash_account);
  console.log(`Node's next keys: ${nextKeys}`);
  console.log(`Node's next keys in hex: ${nextKeys.toHex()}`);
  let nodeHasKeys = await api.rpc.author.hasSessionKeys(nextKeys.toHex());
  console.log(`Node has keys: ${nodeHasKeys}`);

The above always returns False, but it looks like I am getting the right data from the chain ({"grandpa":"0x90cac etc...).

How to make the above work? I tried hasSessionKeys(nextKeys) as well without .toHex() but it didn't work either.

I am trying on Kusama but I'd like the above to work on Polkadot too.

1 Answer 1

3

Replying to myself. It actually works the way I described it, not sure why I thought otherwise initially.

  let nextKeys = await api.query.session.nextKeys(stash_account);
  let nodeHasKeys = await api.rpc.author.hasSessionKeys(nextKeys.toHex());
  if (nodeHasKeys.isFalse()) {
    console.error(`Node does not have the expected session keys.`);
  }

Here is a complete session key check script: https://github.com/midl-dev/polkadot-k8s/blob/master/polkadot-session-key-check/index.ts

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.