Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/StateDiff

primitives/StateDiff

Type Aliases

AccountDiff

AccountDiff = object
Defined in: src/primitives/StateDiff/StateDiffType.ts:37 Account state changes during transaction execution Captures all state modifications for a single account. Used extensively by debug_traceTransaction with prestateTracer.

Properties

balance?
readonly optional balance: BalanceChange
Defined in: src/primitives/StateDiff/StateDiffType.ts:38
code?
readonly optional code: CodeChange
Defined in: src/primitives/StateDiff/StateDiffType.ts:40
nonce?
readonly optional nonce: NonceChange
Defined in: src/primitives/StateDiff/StateDiffType.ts:39
storage?
readonly optional storage: ReadonlyMap<StorageKeyType, { from: StorageValueType | null; to: StorageValueType | null; }>
Defined in: src/primitives/StateDiff/StateDiffType.ts:41

BalanceChange

BalanceChange = object
Defined in: src/primitives/StateDiff/StateDiffType.ts:10 Balance change (before/after)

Properties

from
readonly from: WeiType | null
Defined in: src/primitives/StateDiff/StateDiffType.ts:11
to
readonly to: WeiType | null
Defined in: src/primitives/StateDiff/StateDiffType.ts:12

CodeChange

CodeChange = object
Defined in: src/primitives/StateDiff/StateDiffType.ts:26 Code change (before/after)

Properties

from
readonly from: Uint8Array | null
Defined in: src/primitives/StateDiff/StateDiffType.ts:27
to
readonly to: Uint8Array | null
Defined in: src/primitives/StateDiff/StateDiffType.ts:28

NonceChange

NonceChange = object
Defined in: src/primitives/StateDiff/StateDiffType.ts:18 Nonce change (before/after)

Properties

from
readonly from: NonceType | null
Defined in: src/primitives/StateDiff/StateDiffType.ts:19
to
readonly to: NonceType | null
Defined in: src/primitives/StateDiff/StateDiffType.ts:20

StateDiffType

StateDiffType = object
Defined in: src/primitives/StateDiff/StateDiffType.ts:71 Complete state changes across all accounts Represents full state diff from debug_traceTransaction prestateTracer. Maps addresses to their account-level changes.

Example

const stateDiff: StateDiffType = {
  accounts: new Map([
    [address1, {
      balance: { from: oldBalance, to: newBalance },
      nonce: { from: 0n, to: 1n },
      storage: new Map([
        [key, { from: null, to: value }]
      ])
    }]
  ])
};

Properties

accounts
readonly accounts: ReadonlyMap<AddressType, AccountDiff>
Defined in: src/primitives/StateDiff/StateDiffType.ts:75 Map of account addresses to their state changes

Variables

StateDiff

const StateDiff: object
Defined in: src/primitives/StateDiff/index.ts:59

Type Declaration

from()
from: (value) => StateDiffType = _from
Create StateDiff from account changes
Parameters
value
Account changes map, array, or object Map<AddressType, AccountDiff> | [AddressType, AccountDiff][] | { accounts: Map<AddressType, AccountDiff>; }
Returns
StateDiffType StateDiff
Example
const diff = StateDiff.from(new Map([[address, { balance: { from: 0n, to: 100n } }]]));
const diff2 = StateDiff.from([[address, { nonce: { from: 0n, to: 1n } }]]);
const diff3 = StateDiff.from({ accounts: accountsMap });
getAccount()
getAccount: (diff, address) => AccountDiff | undefined
Parameters
diff
StateDiffType | Map<AddressType, AccountDiff>
address
AddressType
Returns
AccountDiff | undefined
getAddresses()
getAddresses: (diff) => AddressType[]
Parameters
diff
StateDiffType | Map<AddressType, AccountDiff>
Returns
AddressType[]
isEmpty()
isEmpty: (diff) => boolean
Parameters
diff
StateDiffType | Map<AddressType, AccountDiff>
Returns
boolean

Functions

_getAccount()

_getAccount(diff, address): AccountDiff | undefined
Defined in: src/primitives/StateDiff/getAccount.js:16 Get account diff for a specific address

Parameters

diff
StateDiffType State diff
address
AddressType Address to look up

Returns

AccountDiff | undefined Account diff or undefined

Example

const accountDiff = StateDiff.getAccount(diff, address);
if (accountDiff?.balance) {
  console.log(`Balance: ${accountDiff.balance.from} -> ${accountDiff.balance.to}`);
}

_getAddresses()

_getAddresses(diff): AddressType[]
Defined in: src/primitives/StateDiff/getAddresses.js:15 Get all addresses with state changes

Parameters

diff
StateDiffType State diff

Returns

AddressType[] Array of addresses

Example

const addresses = StateDiff.getAddresses(diff);
for (const addr of addresses) {
  console.log(`Account ${Address.toHex(addr)} changed`);
}

_isEmpty()

_isEmpty(diff): boolean
Defined in: src/primitives/StateDiff/isEmpty.js:14 Check if state diff has any changes

Parameters

diff
StateDiffType State diff

Returns

boolean True if no accounts have changes

Example

if (!StateDiff.isEmpty(diff)) {
  console.log("State was modified");
}

from()

from(value): StateDiffType
Defined in: src/primitives/StateDiff/from.js:14 Create StateDiff from account changes

Parameters

value
Account changes map, array, or object Map<AddressType, AccountDiff> | [AddressType, AccountDiff][] | { accounts: Map<AddressType, AccountDiff>; }

Returns

StateDiffType StateDiff

Example

const diff = StateDiff.from(new Map([[address, { balance: { from: 0n, to: 100n } }]]));
const diff2 = StateDiff.from([[address, { nonce: { from: 0n, to: 1n } }]]);
const diff3 = StateDiff.from({ accounts: accountsMap });

getAccount()

getAccount(diff, address): AccountDiff | undefined
Defined in: src/primitives/StateDiff/index.ts:18

Parameters

diff
StateDiffType | Map<AddressType, AccountDiff>
address
AddressType

Returns

AccountDiff | undefined

getAddresses()

getAddresses(diff): AddressType[]
Defined in: src/primitives/StateDiff/index.ts:31

Parameters

diff
StateDiffType | Map<AddressType, AccountDiff>

Returns

AddressType[]

isEmpty()

isEmpty(diff): boolean
Defined in: src/primitives/StateDiff/index.ts:43

Parameters

diff
StateDiffType | Map<AddressType, AccountDiff>

Returns

boolean