@tevm/state
The @tevm/state
package provides a robust state management system for Tevm, handling Ethereum account states, contract storage, and state transitions. It offers both synchronous and asynchronous APIs for managing the EVM state.
Installation
npm install @tevm/state
Overview
The state package is responsible for:
- Managing account states (balance, nonce, code, storage)
- Handling state transitions and checkpoints
- Caching and persistence of state data
- Supporting forked chain states
- Providing efficient state access and modification
API Reference
Enumerations
- CacheType - Types of caching mechanisms
Core Types
State Management
- StateManager - Main interface for state operations
- BaseState - Core state data structure
- TevmState - Tevm-specific state representation
- StateAction - Type for state modification actions
- StateOptions - State configuration options
- StateRoots - State roots mapping
- ParameterizedTevmState - Parameterized state type
Storage Types
- AccountStorage - Account storage structure
- ParameterizedAccountStorage - Parameterized account storage interface
- SerializableTevmState - Serializable state format
- ForkOptions - Options for forking state
Caching
- StateCache - State caching structure
- AccountCache - Account-level cache
- ContractCache - Contract-level cache
- StorageCache - Storage-level cache
Core Functions
State Creation and Management
- createStateManager - Creates a new state manager instance
- createBaseState - Creates the core state data structure
- deepCopy - Creates deep copy of state
- shallowCopy - Creates shallow copy
State Operations
- getAccount - Retrieves account state
- putAccount - Updates account state
- deleteAccount - Removes an account
- getContractCode - Gets contract bytecode
- putContractCode - Updates contract bytecode
- getContractStorage - Gets contract storage
- putContractStorage - Updates contract storage
- clearContractStorage - Clears contract storage
- getAccountAddresses - Gets account addresses
- getAppliedKey - Gets applied storage key
- modifyAccountFields - Modifies account fields
State Root Management
- getStateRoot - Gets current state root
- setStateRoot - Sets new state root
- hasStateRoot - Checks if state root exists
Checkpointing and Committing
- checkpoint - Creates a state checkpoint
- commit - Commits state changes
- revert - Reverts to previous checkpoint
Cache Management
- clearCaches - Clears all state caches
- originalStorageCache - Manages original storage cache
Genesis and Forking
- dumpCanonicalGenesis - Dumps canonical genesis state
- generateCanonicalGenesis - Generates canonical genesis
- getForkBlockTag - Gets fork block tag
- getForkClient - Gets fork client
Storage Operations
- dumpStorage - Dumps storage state
- dumpStorageRange - Dumps storage range
- getProof - Gets state proof
Usage Examples
Creating a State Manager