{"record":{"id":"3f453ad325554ac6","repo":"linera-io/linera-protocol","slug":"no-chain-id-specified-and-no-default-chain-in-wall","errorCode":null,"errorMessage":"No chain ID specified and no default chain in wallet","messagePattern":"No chain ID specified and no default chain in wallet","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-service/src/cli/main.rs","lineNumber":1285,"sourceCode":"                    }\n                    if raw {\n                        println!(\"{}\", serde_json::to_string(&notification)?);\n                    }\n                }\n                info!(\"Notification stream ended.\");\n            }\n\n            QueryApplication {\n                chain_id,\n                application_id,\n                query,\n            } => {\n                let context = options\n                    .create_client_context(storage, wallet, keystore)\n                    .await?;\n                let chain_id = chain_id\n                    .or_else(|| context.wallet().default_chain())\n                    .expect(\"No chain ID specified and no default chain in wallet\");\n                let chain_client = context.make_chain_client(chain_id).await?;\n                let graphql_query = format!(\"query {{ {query} }}\");\n                let json_query = serde_json::json!({ \"query\": graphql_query });\n                let query_bytes = serde_json::to_vec(&json_query)?;\n                let query = linera_execution::Query::User {\n                    application_id,\n                    bytes: query_bytes,\n                };\n                let (outcome, _height) = chain_client.query_application(query, None).await?;\n                match outcome.response {\n                    linera_execution::QueryResponse::User(bytes) => {\n                        let response: Value = serde_json::from_slice(&bytes)?;\n                        let data = &response[\"data\"];\n                        println!(\"{data}\");\n                    }\n                    linera_execution::QueryResponse::System(_) => {\n                        unreachable!(\"cannot get a system response for a user query\")\n                    }","sourceCodeStart":1267,"sourceCodeEnd":1303,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-service/src/cli/main.rs#L1267-L1303","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass --chain-id <chain-id-of-the-applications-owner> explicitly on the command","Set a wallet default first: `linera wallet set-default <chain_id>` (see WalletCommand::SetDefault)","If the wallet is empty, create/assign a chain first (`linera wallet init`, then create or assign a chain) so a default exists","Persist the intended chain in your deployment script instead of relying on wallet state"],"exampleFix":"# before\nlinera query-application e5... --json-graphql-style-query 'query { ... }'\n\n# after\nlinera wallet set-default 4ee5..c0de\nlinera query-application e5... --chain-id 4ee5..c0de 'query { ... }'","handlingStrategy":"validation","validationCode":"# Fail early with a clear message instead of letting the CLI panic.\nDEFAULT_CHAIN=$(linera wallet --json 2>/dev/null | jq -r '.default_chain // empty')\nCHAIN_ID=${CHAIN_ID:-$DEFAULT_CHAIN}\n[ -n \"$CHAIN_ID\" ] || { echo 'no --chain-id and no default chain; run: linera wallet set-default <chain>' >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --chain-id in scripts instead of relying on wallet state","Run `linera wallet set-default <chain_id>` immediately after wallet init/assign","After forgetting keys, re-set the default chain as part of the same runbook step"],"tags":["linera","cli","wallet","chain-id","default-chain"],"backgroundTag":"missing-default-chain","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}