Previous Module
Security Best Practices Game

🐛 Transaction Debugging: Fix Failed Transactions

Learn how to decode revert reasons and trace execution

🐛 Why Transactions Fail

Failed transactions are inevitable in smart contract development. Whether you're building a DeFi protocol, NFT marketplace, or DAO, you'll encounter cryptic errors like "execution reverted", "out of gas", or "invalid opcode". Each failed transaction costs gas but provides zero functionality—burning user funds for nothing. Worse, users see generic error messages and lose trust in your dApp. Transaction debugging is the skill that separates junior devs from production engineers. You must decode revert reasons, trace execution paths, profile gas usage, and fix root causes—not just symptoms. This module teaches systematic debugging using real tools: Etherscan, Hardhat, Tenderly, and custom trace scripts.

🎮 Interactive: Common Error Types

Explore the 4 most common transaction failure types. Click each to see examples, debugging strategies, and root causes.

🚫

Revert

Contract explicitly reverted with a message

Example
require(balance >= amount, "Insufficient balance")
Transaction
0x1a2b3c4d...failed
💸 Cost Impact

Gas used up to revert point

🔍 How to Debug
  1. 1Check revert message in transaction logs
  2. 2Look for require() or revert() statements in contract
  3. 3Verify input parameters meet contract requirements
  4. 4Check contract state before transaction
⚠️ Common Causes
  • Insufficient balance for transfer
  • Invalid permissions (not owner)
  • Time-based restrictions not met
  • Invalid input parameters

🛠️ Essential Debugging Tools

Etherscan: View transaction details, decode input/output, check internal txs, read state changes.
Hardhat Console: Run transactions locally, get full stack traces, inspect storage, debug step-by-step.
Tenderly: Visual debugger with transaction simulation, gas profiling, state diffs, collaborative debugging.
Custom Scripts: Write debug scripts to replay transactions, decode custom errors, analyze event logs.

📊 Transaction Failure Statistics

Revert (explicit)
45%
Out of Gas
30%
Invalid Opcode
15%
Other (underflow, bad jump)
10%

Based on 1M+ failed transactions analyzed across Ethereum mainnet (2023-2024)

💡 Debugging Mindset

  • Start with the error message: Read it carefully. "Insufficient balance" tells you exactly what's wrong.
  • Reproduce locally: Failed on mainnet? Fork the state, replay the tx in Hardhat, get full stack trace.
  • Check inputs first: 80% of failures are invalid inputs (wrong address, insufficient approval, expired signature).
  • Use binary search: Comment out half the code, retry. Narrows down the failing statement quickly.
  • Read the contract: Etherscan shows verified source. Read the require() conditions and understand the logic.