linera-io/linera-protocol · error

Service requires a default chain in the wallet

Error message

Service requires a default chain in the wallet

What it means

The `linera service` node command resolves the hosting chain from the wallet's default chain and panics with 'Service requires a default chain in the wallet' when default_chain() returns None. Unlike query-application, this command has no --chain-id override, so the default chain is mandatory.

Source

Thrown at linera-service/src/cli/main.rs:1328

                #[cfg(with_metrics)]
                metrics_port,
                operator_application_ids,
                operators,
                controller_application_id,
                task_retry_delay_secs,
                read_only,
                query_cache_size,
                allowed_subscriptions,
                subscription_ttls,
                pause,
            } => {
                let context = options
                    .create_client_context(storage, wallet, keystore)
                    .await?;

                let default_chain = context.wallet().default_chain();
                let chain_id =
                    default_chain.expect("Service requires a default chain in the wallet");

                assert!(
                    operator_application_ids.is_empty() || controller_application_id.is_none(),
                    "Cannot run a static list of applications when a controller is given."
                );

                let cancellation_token = CancellationToken::new();
                tokio::spawn(listen_for_shutdown_signals(cancellation_token.clone()));

                let operators: BTreeMap<String, PathBuf> = operators.into_iter().collect();
                for (name, path) in &operators {
                    info!("Operator '{}' -> {}", name, path.display());
                }
                let operators = Arc::new(operators);

                // Start the task processor if operator applications are specified.
                let retry_delay = TimeDelta::from_secs(task_retry_delay_secs);

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Run `linera wallet set-default <chain_id>` with an existing chain before starting the service
  2. If the wallet has no chains yet, initialize it and create/assign a chain first (`linera wallet init`, then create-own-chain or assign)
  3. Verify LINERA_WALLET_HOME / --wallet points at the wallet you actually use for applications
  4. Bake the set-default step into the service startup script so environment resets cannot reproduce the panic

Example fix

# before
linera service --port 8080   # panics: no default chain

# after
linera wallet set-default 4ee5..c0de
linera service --port 8080
Defensive patterns

Strategy: validation

Validate before calling

# Pre-flight for the service command (which has no --chain-id override).
linera wallet --help >/dev/null
DEFAULT=$(jq -r '.default_chain // empty' "$LINERA_WALLET_HOME/wallet.json" 2>/dev/null)
[ -n "$DEFAULT" ] || { echo 'set a default chain first: linera wallet set-default <chain_id>' >&2; exit 1; }

Prevention

When it happens

Trigger: Starting `linera service` with a wallet that has no default chain: brand-new wallet file, wallet where all chains were forgotten, or a wallet assembled by importing keys without assigning a chain as default.

Common situations: Running the GraphQL/node service in a container or CI with a fresh wallet that was never initialized with a chain; after `linera wallet forget-keys` removed the last chain; mismatched LINERA_WALLET_HOME pointing at an empty wallet.

Related errors


AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22). Data as JSON: /api/errors/ebdc1769b6c468e6. Report an issue: GitHub.