Skip to main content

StateDiff

Complete state changes across all accounts during transaction execution. Primary output from debug_traceTransaction with prestateTracer.

Overview

StateDiff captures all state modifications: balance changes, nonce increments, code deployments, and storage updates. Essential for state analysis and forensics.

Type Definition

Usage

Creating State Diffs

Querying State Changes

prestateTracer Integration

Primary use case for StateDiff:

Account Changes

Balance Changes

ETH transfers modify balances:

Nonce Increments

Transaction execution increments sender nonce:

Contract Deployment

Code deployment creates new contract:

Storage Updates

Contract storage modifications:

Analysis Patterns

Transaction Impact

Analyze full transaction impact:

Gas Cost Estimation

Calculate state change costs:

Forensics

Investigate suspicious transactions:

API Reference

Constructors

  • StateDiff.from(accounts) - Create from Map/array
  • StateDiff.from({ accounts }) - Create from object

Methods

  • StateDiff.getAccount(diff, address) - Get account changes
  • StateDiff.getAddresses(diff) - Get all modified addresses
  • StateDiff.isEmpty(diff) - Check if state was modified

See Also