Paj Digital Labs
All articles
Web3 & Crypto Tech

Reading a Blockchain Transaction Like an Engineer: Gas, Logs and Traces

Block explorers show you a summary. Engineers need the full story: what gas actually paid for, how event logs work, and how traces reveal what really happened inside a failed transaction.

Paj Digital Labs 3 min read
Hardware security key beside a connected circuit board
Editorial illustration · Web3 & Crypto Tech

A user reports that their transaction "failed but still took my money." On the block explorer you see a red status and a fee. To answer them properly — and to fix whatever caused it — you need to read the transaction the way the network actually processed it.

The anatomy of a transaction

An EVM transaction has a small number of fields that matter:

| Field | Meaning | |---|---| | from / to | Sender and target contract or address | | value | Native currency sent | | input (data) | Encoded function call and arguments | | gas limit | Maximum computation the sender will pay for | | max fee / priority fee | Price per unit of gas | | nonce | Sender's transaction counter |

The input data is where the meaning lives. The first four bytes are the function selector — a hash of the function signature. The rest is ABI-encoded arguments.

text
0xa9059cbb                                  -> transfer(address,uint256)
000000000000000000000000ab12...ef34         -> recipient
00000000000000000000000000000000000000000000000000000000000f4240 -> 1,000,000

With the contract's ABI you can decode this into a readable call. Most libraries do this in one line.

Why failed transactions still cost money

Gas pays for computation, not for success. Validators executed your transaction up to the point where it reverted, and that work is paid for. A failed transaction burns the gas consumed up to the revert — which is why "failed but took my money" is accurate, just not in the way the user means. Their tokens did not move; the fee did.

This is also why wallets simulate transactions before sending. If a simulation predicts a revert, the wallet warns the user before they pay.

Receipts and event logs

After execution, the transaction gets a receipt: status, gas used, and logs. Logs are how contracts announce what happened. A token transfer emits a Transfer event; a swap emits a Swap event.

Each log has:

  • The contract address that emitted it
  • Up to four topics — the first is the event signature hash, the rest are indexed parameters
  • A data field with non-indexed parameters

Logs are what your backend should watch. They are cheap to query, indexed by topic, and they reflect what actually happened rather than what the caller intended.

ts
const logs = await client.getLogs({
  address: TOKEN,
  event: parseAbiItem(class="text-code-string">"event Transfer(address indexed from, address indexed to, uint256 value)"),
  args: { to: MY_ADDRESS },
  fromBlock: start,
});

One important rule: logs from a reverted transaction do not exist. If it reverted, nothing was emitted.

Traces: what happened inside

A single transaction can call dozens of contracts. A swap through an aggregator might touch a router, several pools and a token contract. The receipt only tells you the final outcome. Traces show every internal call, its inputs, outputs and gas.

When a transaction reverts deep inside a call chain, the trace shows exactly which internal call failed and, usually, the revert reason. Common reasons:

  • Slippage exceeded — the price moved before execution
  • Insufficient allowance — the user had not approved the contract to spend the token
  • Deadline passed — the transaction waited too long in the mempool
  • Out of gas — the gas limit was too low for the path taken

Trace APIs are not available on every node by default. Many hosted node providers offer them as an add-on, or you can use a local fork to replay the transaction with full tracing.

Nonces and stuck transactions

If a transaction with nonce 14 is stuck because its fee was too low, every later transaction from that address waits behind it. The fix is to send a new transaction with the same nonce and a higher fee, either repeating the intended action or sending zero value to yourself to cancel it.

Putting it together for support

When a user reports a problem, I check in this order: status and gas used, decoded input, logs emitted, then trace if it reverted. Ninety percent of the time the answer is slippage, allowance or a stuck nonce — and being able to explain which one, clearly, turns an angry user into a patient one.

Paj Digital Labs

The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.

Related reading