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

primitives/StateRoot

Type Aliases

StateRootLike

StateRootLike = StateRootType | string | Uint8Array
Defined in: src/primitives/StateRoot/StateRootType.ts:23 Inputs that can be converted to StateRoot

StateRootType

StateRootType = Uint8Array & object
Defined in: src/primitives/StateRoot/StateRootType.ts:15 Branded StateRoot type - represents a 32-byte Merkle Patricia Trie root hash of the global Ethereum state. The state root is the root hash of the state trie, which contains mappings from addresses to account states. It uniquely identifies the entire global state at a given block. Per the Yellow Paper, the state trie encodes mappings between addresses (160-bit identifiers) and account states. The state root is included in every block header.

Type Declaration

[brand]
readonly [brand]: "StateRoot"
length
readonly length: 32

Variables

SIZE

const SIZE: 32 = 32
Defined in: src/primitives/StateRoot/StateRootType.ts:25

Functions

equals()

equals(a, b): boolean
Defined in: src/primitives/StateRoot/equals.js:20 Compares two StateRoots for equality. Uses constant-time comparison to prevent timing attacks.

Parameters

a
StateRootType First StateRoot
b
StateRootType Second StateRoot

Returns

boolean
  • True if equal

Example

const isEqual = StateRoot.equals(root1, root2);

from()

from(value): StateRootType
Defined in: src/primitives/StateRoot/from.js:21 Creates a StateRoot from various input types. Accepts hex strings, Uint8Array, or existing StateRoot instances.

Parameters

value
StateRootLike The value to convert

Returns

StateRootType
  • A branded StateRoot

Example

const root = StateRoot.from("0x1234...");
const root2 = StateRoot.from(new Uint8Array(32));

fromHex()

fromHex(hex): StateRootType
Defined in: src/primitives/StateRoot/fromHex.js:18 Creates a StateRoot from a hex string.

Parameters

hex
string Hex string (with or without 0x prefix)

Returns

StateRootType
  • A branded StateRoot

Example

const root = StateRoot.fromHex("0x1234...");

toHex()

toHex(stateRoot): string
Defined in: src/primitives/StateRoot/toHex.js:19 Converts a StateRoot to a hex string.

Parameters

stateRoot
StateRootType The StateRoot to convert

Returns

string
  • Hex string with 0x prefix

Example

const hex = StateRoot.toHex(root);
// "0x1234..."