{"record":{"id":"cf6bc073d2db274b","repo":"nautechsystems/nautilus_trader","slug":"query-account-request-failure-account-should-exis","errorCode":null,"errorMessage":"Query account request failure, account should exist","messagePattern":"Query account request failure, account should exist","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/grpc/client.rs","lineNumber":295,"sourceCode":"    /// Query account information for a given address.\n    ///\n    /// Returns the account number and sequence number needed for transaction signing.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the query fails or the account does not exist.\n    pub async fn query_address(&mut self, address: &str) -> Result<(u64, u64), anyhow::Error> {\n        let req = QueryAccountRequest {\n            address: address.to_string(),\n        };\n        let resp = self\n            .auth\n            .account(req)\n            .await?\n            .into_inner()\n            .account\n            .ok_or_else(|| {\n                anyhow::anyhow!(\"Query account request failure, account should exist\")\n            })?;\n\n        let account = BaseAccount::decode(&*resp.value)?;\n        Ok((account.account_number, account.sequence))\n    }\n\n    /// Query for [an account](https://github.com/cosmos/cosmos-sdk/tree/main/x/auth#account-1)\n    /// by its address.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the query fails or the account does not exist.\n    pub async fn get_account(&mut self, address: &str) -> Result<BaseAccount, anyhow::Error> {\n        let req = QueryAccountRequest {\n            address: address.to_string(),\n        };\n        let resp = self\n            .auth","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/grpc/client.rs#L277-L313","documentation":"query_address queries the cosmos auth module for an account by address; the gRPC response's optional `account` field is None when the account does not exist on chain. The library treats this as fatal because it needs account_number/sequence to sign transactions.","triggerScenarios":"Calling query_address for an address that has never been funded or has not sent/received any transaction on the dydx chain.","commonSituations":"Using a freshly generated wallet key with no on-chain activity; wrong network (testnet address queried on mainnet RPC); typo'd or malformed bech32 address prefix.","solutions":["Fund the account or send any transaction to it so the BaseAccount is created on chain.","Verify the address is valid for the connected network (correct bech32 prefix dydx...).","Point the gRPC client at the correct network endpoint for the account.","Handle the empty case in caller code by treating it as account-not-found rather than retrying."],"exampleFix":"// before\nlet (number, seq) = client.query_address(addr).await?;\n// after: ensure account exists on chain first\nmatch client.query_address(addr).await {\n    Ok(res) => res,\n    Err(e) if e.to_string().contains(\"account should exist\") => {\n        anyhow::bail!(\"Account {addr} has no on-chain state; fund it or use a different address\")\n    }\n    Err(e) => Err(e),\n}","handlingStrategy":"validation","validationCode":"let info = key_info.address();\nanyhow::ensure!(info.starts_with(\"dydx\"), \"address {info} has wrong bech32 prefix\");","typeGuard":null,"tryCatchPattern":"match client.query_address(addr).await {\n    Ok(res) => res,\n    Err(e) if e.to_string().contains(\"account should exist\") => anyhow::bail!(\"account {addr} not initialized on chain; fund it first\"),\n    Err(e) => Err(e),\n}","preventionTips":["Fund new wallets before running trading logic","Pin the network endpoint and address prefix per environment","Check account existence at startup, not at trade time"],"tags":["grpc","cosmos","account","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}