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.
import * as StorageValue from '@voltaire/primitives/StorageValue';// From bigintconst val1 = StorageValue.from(123n);// From hex stringconst val2 = StorageValue.from("0x0000000000000000000000000000000000000000000000000000000000000001");// From Uint8Array (must be 32 bytes)const val3 = StorageValue.from(new Uint8Array(32));
Create from hex string (with or without 0x prefix):
import * as StorageValue from '@voltaire/primitives/StorageValue';const val = StorageValue.fromHex("0x0000000000000000000000000000000000000000000000000000000000000064");
import * as StorageValue from '@voltaire/primitives/StorageValue';const val = StorageValue.from(123n);const hex = StorageValue.toHex(val);// "0x000000000000000000000000000000000000000000000000000000000000007b"
Compare two StorageValues using constant-time comparison (timing-attack safe):
import * as StorageValue from '@voltaire/primitives/StorageValue';const a = StorageValue.from(100n);const b = StorageValue.from(100n);const c = StorageValue.from(200n);StorageValue.equals(a, b); // trueStorageValue.equals(a, c); // false
import * as StorageValue from '@voltaire/primitives/StorageValue';// Slot 0 typically stores first state variableconst slot0 = StorageValue.from(0n);// ERC-20 balances often at slot 0 (mapping)const balanceSlot = StorageValue.from( "0x0000000000000000000000000000000000000000000000000000000000000000");