Skip to content

After setting up your node environment as shown in the Setup section, you'll need to configure multiple keys for your validator to operate properly. This includes setting up session keys, which are essential for participating in the consensus process, and configuring a node key that maintains a stable network identity. This guide walks you through the key management process, showing you how to generate, store, and register these keys.

Setting up your validator's session keys is essential to associate your node with your stash account on the Polkadot network. Validators use session keys to participate in the consensus process. Your validator can only perform its role in the network by properly setting session keys which consist of several key pairs for different parts of the protocol (e.g., GRANDPA, BABE). These keys must be registered on-chain and associated with your validator node to ensure it can participate in validating blocks.

Generate session keys by running the following command on your node, replacing INSERT_STASH_ACCOUNT_ID with your stash account ID:

Terminal window
curl -H "Content-Type: application/json" \
-d '{"id":1, "jsonrpc":"2.0", "method": "author_rotateKeysWithOwner", "params":["INSERT_STASH_ACCOUNT_ID"]}' \
http://localhost:9944

This command returns a JSON object with two fields in the result: keys (the hex-encoded session keys) and proof (the ownership proof). Save both values for later use.

{
"jsonrpc": "2.0",
"result": {
"keys": "0xda3861a45e0197f3ca145c2c209f9126e5053fas503e459af4255cf8011d51010",
"proof": "0x1a2b3c4d5e6f..."
},
"id": 1
}

After generating your session keys (and proof, if using runtime 2.2.0+), you must submit them on-chain. There are two paths for submitting session keys:

The recommended approach is to use the stakingRcClient.set_keys extrinsic on Polkadot Hub. This path is required for validators using pure proxy stash accounts or Staking Operator proxies.

  1. In Polkadot.js Apps, connect to Polkadot Hub (Asset Hub).
  2. Navigate to Developer > Extrinsics.
  3. Select your stash account (or submit via proxy).
  4. Choose the stakingRcClient pallet and the setKeys extrinsic.
  5. Enter the following parameters:
    • keys: The session keys hex string returned by author_rotateKeysWithOwner.
    • proof: The proof hex string returned by author_rotateKeysWithOwner.
    • maxDeliveryAndRemoteExecutionFee: Optional maximum fee for the XCM message to the relay chain. Can be left as None.
  6. Submit and sign the transaction.

Polkadot Hub validates the proof locally and forwards the keys to the relay chain via XCM.

Once the transaction is signed and submitted, your session keys will be registered on-chain.

To verify that your session keys are properly set, you can use one of two RPC calls:

  • hasKey: Checks if the node has a specific key by public key and key type.
  • hasSessionKeys: Verifies if your node has the full session key string associated with the validator.

For example, you can check session keys on the Polkadot.js Apps interface or by running an RPC query against your node. Once this is done, your validator node is ready for its role.

Validators and collators on Polkadot need a static network key (also known as the node key) to maintain a stable node identity. This key ensures that your node can maintain a consistent peer ID, even across restarts, which is crucial for maintaining reliable network connections.

Starting with Polkadot version 1.11, validators without a stable network key may encounter the following error on startup:

polkadot --validator --name "INSERT_NAME_FROM_TELEMETRY" Error: 0: Starting an authority without network key This is not a safe operation because other authorities in the network may depend on your node having a stable identity. Otherwise these other authorities may not being able to reach you. If it is the first time running your node you could use one of the following methods: 1. [Preferred] Separately generate the key with: INSERT_NODE_BINARY key generate-node-key --base-path INSERT_YOUR_BASE_PATH 2. [Preferred] Separately generate the key with: INSERT_NODE_BINARY key generate-node-key --file INSERT_YOUR_PATH_TO_NODE_KEY 3. [Preferred] Separately generate the key with: INSERT_NODE_BINARY key generate-node-key --default-base-path 4. [Unsafe] Pass --unsafe-force-node-key-generation and make sure you remove it for subsequent node restarts

Follow these steps to generate a node key:

  1. Generate your node key using one of the following options:

    Terminal window
    docker run --rm parity/subkey:latest generate-node-key > node.key
  2. Locate your peer ID in the displayed output. The peer ID is similar to this example:

    12D3KooWExcVYu7Mvjd4kxPVLwN2ZPnZ5NyLZ5ft477wqzfP2q6E

Be sure to save the peer ID for future reference.

After generating the node key, configure your node to use it by specifying the path to the key file when launching your node. Add the following flag to your validator node's startup command:

Terminal window
polkadot --node-key-file INSERT_PATH_TO_NODE_KEY

Following these steps ensures that your node retains its identity, making it discoverable by peers without the risk of conflicting identities across sessions. For further technical background, see Polkadot SDK Pull Request #3852 for the rationale behind requiring static keys.

Last updated: