linera-io/linera-protocol · error

No chain ID specified and no default chain in wallet

Error message

No chain ID specified and no default chain in wallet

What it means

For the query-application CLI command, the target chain is resolved as the --chain-id argument, falling back to the wallet's default chain. If neither is present, .expect("No chain ID specified and no default chain in wallet") panics before the query is sent. The wallet simply has no default chain set (fresh wallet, or default was cleared by forgetting keys).

Source

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

                    }
                    if raw {
                        println!("{}", serde_json::to_string(&notification)?);
                    }
                }
                info!("Notification stream ended.");
            }

            QueryApplication {
                chain_id,
                application_id,
                query,
            } => {
                let context = options
                    .create_client_context(storage, wallet, keystore)
                    .await?;
                let chain_id = chain_id
                    .or_else(|| context.wallet().default_chain())
                    .expect("No chain ID specified and no default chain in wallet");
                let chain_client = context.make_chain_client(chain_id).await?;
                let graphql_query = format!("query {{ {query} }}");
                let json_query = serde_json::json!({ "query": graphql_query });
                let query_bytes = serde_json::to_vec(&json_query)?;
                let query = linera_execution::Query::User {
                    application_id,
                    bytes: query_bytes,
                };
                let (outcome, _height) = chain_client.query_application(query, None).await?;
                match outcome.response {
                    linera_execution::QueryResponse::User(bytes) => {
                        let response: Value = serde_json::from_slice(&bytes)?;
                        let data = &response["data"];
                        println!("{data}");
                    }
                    linera_execution::QueryResponse::System(_) => {
                        unreachable!("cannot get a system response for a user query")
                    }

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Pass --chain-id <chain-id-of-the-applications-owner> explicitly on the command
  2. Set a wallet default first: `linera wallet set-default <chain_id>` (see WalletCommand::SetDefault)
  3. If the wallet is empty, create/assign a chain first (`linera wallet init`, then create or assign a chain) so a default exists
  4. Persist the intended chain in your deployment script instead of relying on wallet state

Example fix

# before
linera query-application e5... --json-graphql-style-query 'query { ... }'

# after
linera wallet set-default 4ee5..c0de
linera query-application e5... --chain-id 4ee5..c0de 'query { ... }'
Defensive patterns

Strategy: validation

Validate before calling

# Fail early with a clear message instead of letting the CLI panic.
DEFAULT_CHAIN=$(linera wallet --json 2>/dev/null | jq -r '.default_chain // empty')
CHAIN_ID=${CHAIN_ID:-$DEFAULT_CHAIN}
[ -n "$CHAIN_ID" ] || { echo 'no --chain-id and no default chain; run: linera wallet set-default <chain>' >&2; exit 1; }

Prevention

When it happens

Trigger: Running `linera query-application` without --chain-id on a wallet whose default_chain() is None — e.g. a newly created wallet, a wallet whose only chain was forgotten, or a wallet created by key-import that never assigned a default.

Common situations: Fresh `linera wallet init && linera keygen` flow where no chain was assigned yet; multi-chain wallet where the default was removed via `linera wallet forget-keys`; scripts running after wallet file regeneration.

Related errors


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