โ†
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.