{"record":{"id":"da677d746c1083c4","repo":"nautechsystems/nautilus_trader","slug":"transaction-broadcast-failed-code-log","errorCode":null,"errorMessage":"Transaction broadcast failed: code={}, log={}","messagePattern":"Transaction broadcast failed: code=(.+?), log=(.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/grpc/client.rs","lineNumber":488,"sourceCode":"            .gas_used;\n        Ok(gas_used)\n    }\n\n    /// Broadcast a signed transaction.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if broadcasting fails.\n    pub async fn broadcast_tx(&mut self, tx_bytes: Vec<u8>) -> Result<TxHash, anyhow::Error> {\n        let req = BroadcastTxRequest {\n            tx_bytes,\n            mode: BroadcastMode::Sync as i32,\n        };\n        let response = self.tx.broadcast_tx(req).await?.into_inner();\n\n        if let Some(tx_response) = response.tx_response {\n            if tx_response.code != 0 {\n                anyhow::bail!(\n                    \"Transaction broadcast failed: code={}, log={}\",\n                    tx_response.code,\n                    tx_response.raw_log\n                );\n            }\n            Ok(tx_response.txhash)\n        } else {\n            Err(anyhow::anyhow!(\n                \"Broadcast response does not contain tx_response\"\n            ))\n        }\n    }\n\n    /// Query transaction by hash.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the query fails.","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/grpc/client.rs#L470-L506","documentation":"`broadcast_tx` submits a transaction to the dYdX chain in sync broadcast mode; if the node's tx_response reports a non-zero code, the TX was rejected and the method bails with the chain's code and raw log. This surfaces on-chain rejection reasons (insufficient fees, sequence mismatch, invalid order, etc.).","triggerScenarios":"Any TX broadcast (order submit/cancel) where the chain returns tx_response.code != 0 — e.g. out-of-gas, wrong account sequence, under-minimum gas price, or rejected msg content.","commonSituations":"Gas price/limit misconfigured relative to network minimums; account sequence desync after a restart; submitting during chain halt or upgrades; malformed order params failing chain validation.","solutions":["Read `code` and `raw_log` in the message — the raw log names the exact chain rejection reason","Refresh the account sequence/number before re-broadcasting","Increase gas limit or set gas price to meet the network minimum","Re-check order parameters against dYdX chain validation rules","Verify node status / chain is not halted for an upgrade"],"exampleFix":"// before: blind retry\nclient.broadcast_tx(tx).await?;\n// after: inspect code/log and resync sequence\nmatch client.broadcast_tx(tx.clone()).await {\n    Err(e) if e.to_string().contains(\"code=32\") => { // sequence mismatch\n        tx_manager.resync_sequence().await?;\n        client.broadcast_tx(tx).await?;\n    }\n    r => r?,\n}","handlingStrategy":"try-catch","validationCode":"// ensure sequence is fresh and gas is sufficient before broadcast\ntx_manager.refresh_account().await?;\ndebug_assert!(tx.gas >= estimated_min_gas);","typeGuard":null,"tryCatchPattern":"match client.broadcast_tx(tx).await {\n    Err(e) => {\n        let msg = e.to_string();\n        if msg.contains(\"code=32\") { tx_manager.resync_sequence().await?; /* retry */ }\n        else if msg.contains(\"out of gas\") || msg.contains(\"fee\") { raise_gas_and_retry(); }\n        else { return Err(e); }\n    }\n    Ok(h) => Ok(h),\n}","preventionTips":["Parse code and raw_log rather than treating all failures alike","Keep account sequence synced, especially after restarts","Set gas limit/price above current network minimums","Monitor chain upgrade schedules that halt broadcasts"],"tags":["dydx","blockchain","transaction","broadcast","gas"],"backgroundTag":"api-error-response","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}