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

primitives/StorageValue

Type Aliases

StorageValueLike

StorageValueLike = StorageValueType | bigint | string | Uint8Array
Defined in: src/primitives/StorageValue/StorageValueType.ts:22 Inputs that can be converted to StorageValue

StorageValueType

StorageValueType = Uint8Array & object
Defined in: src/primitives/StorageValue/StorageValueType.ts:14 Branded StorageValue type - represents a 32-byte EVM storage slot value. In the EVM, each contract has 2^256 storage slots, and each slot stores a 32-byte (256-bit) value. Storage is the persistent key-value store used by smart contracts to maintain state between transactions. Storage slots start at zero and are lazily allocated - reading an uninitialized slot returns zero, and writing zero to a slot can trigger a gas refund.

Type Declaration

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

Variables

SIZE

const SIZE: 32 = 32
Defined in: src/primitives/StorageValue/StorageValueType.ts:24

Functions

equals()

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

Parameters

a
StorageValueType First StorageValue
b
StorageValueType Second StorageValue

Returns

boolean
  • True if equal

Example

const isEqual = StorageValue.equals(val1, val2);

from()

from(value): StorageValueType
Defined in: src/primitives/StorageValue/from.js:22 Creates a StorageValue from various input types. Accepts bigint, hex strings, Uint8Array, or existing StorageValue instances.

Parameters

value
StorageValueLike The value to convert

Returns

StorageValueType
  • A branded StorageValue

Example

const val = StorageValue.from(123n);
const val2 = StorageValue.from("0x1234...");
const val3 = StorageValue.from(new Uint8Array(32));

fromHex()

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

Parameters

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

Returns

StorageValueType
  • A branded StorageValue

Example

const val = StorageValue.fromHex("0x1234...");

toHex()

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

Parameters

value
StorageValueType The StorageValue to convert

Returns

string
  • Hex string with 0x prefix

Example

const hex = StorageValue.toHex(val);
// "0x0000000000000000000000000000000000000000000000000000000000000123"

toUint256()

toUint256(value): bigint
Defined in: src/primitives/StorageValue/toUint256.js:18 Converts a StorageValue to a bigint (Uint256).

Parameters

value
StorageValueType The StorageValue to convert

Returns

bigint
  • The numeric value as bigint

Example

const val = StorageValue.from(123n);
const num = StorageValue.toUint256(val);
// 123n