Skip to main content

Try it Live

Run StorageValue examples in the interactive playground

StorageValue

A branded type representing a 32-byte (256-bit) EVM storage slot value. In the EVM, each contract has 2^256 storage slots, and each slot stores exactly 32 bytes.

Overview

StorageValueType provides:
  • Compile-time type branding via Uint8Array
  • 32-byte fixed size validation
  • Conversion to/from hex strings and bigint
  • Constant-time equality comparison

Type Definition

Constants

Construction

from

Create from bigint, hex string, or Uint8Array:

fromHex

Create from hex string (with or without 0x prefix):

Conversion

toHex

Convert to 0x-prefixed hex string:

toUint256

Convert to bigint:

Comparison

equals

Compare two StorageValues using constant-time comparison (timing-attack safe):

EVM Storage Mechanics

Storage in the EVM is a key-value store where:
  • Keys are 256-bit (32-byte) slot indices
  • Values are 256-bit (32-byte) words
  • Uninitialized slots return zero
  • Writing zero can trigger gas refunds

Use Cases

  • Reading/writing contract storage via JSON-RPC
  • EVM execution and state management
  • Storage proof verification
  • State diff analysis
  • Contract state inspection tools

Example: Storage Access

API Reference