{"record":{"id":"1f5e27421c5593d5","repo":"nautechsystems/nautilus_trader","slug":"failed-to-decode-eth-getcode-result-e","errorCode":null,"errorMessage":"Failed to decode eth_getCode result: {e}","messagePattern":"Failed to decode eth_getCode result: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/rpc/http.rs","lineNumber":422,"sourceCode":"        B256::from_str(&value)\n            .map_err(|_| anyhow::anyhow!(\"Failed to parse eth_getStorageAt response\"))\n    }\n\n    async fn get_code_with_block(\n        &self,\n        address: &Address,\n        block: Option<u64>,\n    ) -> anyhow::Result<Bytes> {\n        let result: Option<String> = self\n            .execute_execution_rpc_call(\n                \"eth_getCode\",\n                serde_json::json!([address, block_parameter(block)]),\n            )\n            .await?;\n        let hex_string = result.ok_or_else(|| anyhow::anyhow!(\"eth_getCode returned no result\"))?;\n        let stripped = hex_string.strip_prefix(\"0x\").unwrap_or(&hex_string);\n        let bytes = hex::decode(stripped)\n            .map_err(|e| anyhow::anyhow!(\"Failed to decode eth_getCode result: {e}\"))?;\n        Ok(Bytes::from(bytes))\n    }\n\n    /// Returns the next nonce for the given address via `eth_getTransactionCount`\n    /// with the `pending` tag, making the pending pool state authoritative.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the RPC call fails or the result is missing or malformed.\n    pub async fn get_transaction_count_pending(&self, address: &Address) -> anyhow::Result<u64> {\n        let result: Option<String> = self\n            .execute_execution_rpc_call(\n                \"eth_getTransactionCount\",\n                serde_json::json!([address, \"pending\"]),\n            )\n            .await?;\n        parse_hex_quantity_result(\"eth_getTransactionCount\", result)\n            .and_then(|v| u64::try_from(v).map_err(Into::into))","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/rpc/http.rs#L404-L440","documentation":"The `eth_getCode` result must be a hex-encoded bytecode string; after stripping an optional `0x` prefix, `hex::decode` is applied. Invalid hex characters or odd-length strings produce this error including the decode error `e`.","triggerScenarios":"Node returns a code string that is not valid hex (corrupted response, non-hex encoding, odd number of hex digits, or embedded whitespace/HTML fragments).","commonSituations":"Proxy mangling the response body, a custom chain encoding code differently, or partial/truncated responses from an overloaded node.","solutions":["Log the raw hex_string to identify the invalid portion","Verify endpoint integrity (no body-rewriting proxies) and retry against the node directly","Fix upstream encoding — ensure 0x-prefixed, even-length hex","Add a sanitize step (trim whitespace, strip 0x) if your node emits stray characters"],"exampleFix":"// before: failing on whitespace in response\nlet bytes = hex::decode(stripped)?;\n// after: sanitize first\nlet cleaned: String = stripped.chars().filter(|c| c.is_ascii_hexdigit()).collect();\nlet bytes = hex::decode(&cleaned)?;","handlingStrategy":"validation","validationCode":"fn is_hex_bytecode(s: &str) -> bool {\n    let body = s.strip_prefix(\"0x\").unwrap_or(s);\n    body.len() % 2 == 0 && body.chars().all(|c| c.is_ascii_hexdigit())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify response integrity when proxies sit between client and node","Sanitize hex strings (strip 0x, trim whitespace) before decoding","Check for truncation on large contracts (increase body size limits on proxies)","Test with a known contract's code after configuring a new endpoint"],"tags":["rpc","hex-parsing","bytecode","decoding"],"backgroundTag":"invalid-argument-format","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"}