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

primitives/AccountState

Type Aliases

AccountStateLike

AccountStateLike = AccountStateType | { balance: WeiType; codeHash: HashType; nonce: NonceType; storageRoot: StateRootType; }
Defined in: src/primitives/AccountState/AccountStateType.ts:51 Inputs that can be converted to AccountState

AccountStateType

AccountStateType = object
Defined in: src/primitives/AccountState/AccountStateType.ts:20 AccountState represents the state of an Ethereum account as defined in the Yellow Paper. Each account in Ethereum has four fields:
  • nonce: Number of transactions sent from this address (for EOAs) or contracts created (for contracts)
  • balance: Amount of Wei owned by this account
  • storageRoot: Root hash of the account’s storage trie (for contracts) or empty hash (for EOAs)
  • codeHash: Hash of the account’s EVM bytecode (for contracts) or hash of empty string (for EOAs)
The global state is a mapping from addresses to account states, represented as a Merkle Patricia Trie. The root of this trie is the state root included in each block header.

See

Yellow Paper section 4.1 - World State

Properties

balance
readonly balance: WeiType
Defined in: src/primitives/AccountState/AccountStateType.ts:31 Account balance in Wei (10^-18 ETH). Can be zero or any positive value up to the total ETH supply.
codeHash
readonly codeHash: HashType
Defined in: src/primitives/AccountState/AccountStateType.ts:45 Keccak256 hash of the account’s EVM bytecode. For EOAs, this is keccak256("") = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470. For contracts, this is the hash of their deployed bytecode.
nonce
readonly nonce: NonceType
Defined in: src/primitives/AccountState/AccountStateType.ts:25 Transaction count (EOA) or number of contract creations (contract account). Starts at 0 and increments with each transaction/creation.
storageRoot
readonly storageRoot: StateRootType
Defined in: src/primitives/AccountState/AccountStateType.ts:38 Root hash of the account’s storage trie. For EOAs (externally owned accounts), this is the empty trie hash. For contracts, this is the root of the Merkle Patricia Trie containing storage slots.

Variables

EMPTY_CODE_HASH

const EMPTY_CODE_HASH: "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
Defined in: src/primitives/AccountState/AccountStateType.ts:64 Standard hash of empty string - used for EOA code hash keccak256("") = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470

EMPTY_TRIE_HASH

const EMPTY_TRIE_HASH: "0x56e81f171bcc55a6ff8345e692c0f86e5b47e5b60e2d8c5ab6c7c9fa0e32d3c5" = "0x56e81f171bcc55a6ff8345e692c0f86e5b47e5b60e2d8c5ab6c7c9fa0e32d3c5"
Defined in: src/primitives/AccountState/AccountStateType.ts:71 Standard hash of empty trie - used for EOA storage root keccak256(rlp([])) = 0x56e81f171bcc55a6ff8345e692c0f86e5b47e5b60e2d8c5ab6c7c9fa0e32d3c5

Functions

createEmpty()

createEmpty(): AccountStateType
Defined in: src/primitives/AccountState/createEmpty.js:28 Creates an empty AccountState representing an EOA (Externally Owned Account) with zero balance and nonce. Empty accounts have:
  • nonce: 0
  • balance: 0 Wei
  • storageRoot: empty trie hash
  • codeHash: empty code hash

Returns

AccountStateType
  • An empty AccountState

Example

const emptyAccount = AccountState.createEmpty();

equals()

equals(a, b): boolean
Defined in: src/primitives/AccountState/equals.js:22 Compares two AccountStates for equality. All four fields must match for accounts to be considered equal.

Parameters

a
AccountStateType First AccountState
b
AccountStateType Second AccountState

Returns

boolean
  • True if all fields are equal

Example

const isEqual = AccountState.equals(state1, state2);

from()

from(state): AccountStateType
Defined in: src/primitives/AccountState/from.js:22 Creates an AccountState from an object with the required fields.

Parameters

state
AccountStateLike Object containing nonce, balance, storageRoot, and codeHash

Returns

AccountStateType
  • A validated AccountState

Example

const state = AccountState.from({
  nonce: Nonce.from(5n),
  balance: Wei.from(1000000000000000000n), // 1 ETH
  storageRoot: StateRoot.from("0x56e8..."),
  codeHash: Hash.from("0xc5d2..."),
});

isContract()

isContract(state): boolean
Defined in: src/primitives/AccountState/isContract.js:22 Checks if an AccountState represents a contract account. A contract account is identified by having a non-empty code hash, meaning it has associated bytecode that can be executed.

Parameters

state
AccountStateType The AccountState to check

Returns

boolean
  • True if the account is a contract

Example

const isContract = AccountState.isContract(account);

isEOA()

isEOA(state): boolean
Defined in: src/primitives/AccountState/isEOA.js:22 Checks if an AccountState represents an EOA (Externally Owned Account). An EOA is identified by having the empty code hash, meaning it has no associated bytecode. EOAs can only send transactions and cannot execute code.

Parameters

state
AccountStateType The AccountState to check

Returns

boolean
  • True if the account is an EOA

Example

const isEOA = AccountState.isEOA(account);