Transaction Broadcasting
A production-grade transaction broadcaster follows this pipeline:
User action → API request
→ Validate request
→ Build tx payload
→ Simulate (eth_call)
→ Send to node (eth_sendRawTransaction)
→ Store tx hash + nonce
→ Watch mempool
→ Wait for confirmations
→ Final state update
Critical implementation details:
Nonce Management: Maintain a local nonce counter per signer. Never rely solely on eth_getTransactionCount — it races under concurrent sends. Use a DB-backed nonce lock or sequential queue per address.
Gas Bumping: If a tx is stuck (not mined after N blocks), re-submit with higher gas (EIP-1559: bump maxPriorityFeePerGas by 10-20%). Keep the same nonce to replace the pending tx.
Re-org Handling: A tx "confirmed" at block N can disappear if a re-org removes that block. Don't finalize state until N confirmations (6 for Ethereum mainnet, 12+ for high-value). On Gnosis Chain, finality is ~2.6 minutes with 5-second block times (Beacon Chain PoS since the Dec 2022 Merge).
Idempotency Keys: Every user-initiated action gets a unique idempotency key. If the same key is re-submitted, return the existing tx result instead of creating a duplicate.
Key Points
- ▸Never trust eth_getTransactionCount for concurrent sends
- ▸Gas bumping replaces stuck txs by reusing the same nonce
- ▸Wait for N confirmations before finalizing state
- ▸Idempotency keys prevent duplicate transactions
- ▸Simulate with eth_call before sending real tx