Overview
TheStateManager manages the blockchain world state, including:
- Account balances and nonces
- Contract deployment and bytecode storage
- Contract storage slots (SLOAD/SSTORE)
- State root computation
StateManager
Manages all accounts and contract storage state.Constructor
Creates a new StateManager wrapping the given storage.Example:
Reference to the underlying Storage instance
Account Operations
Gets an account, returning default (zero balance/nonce) if not found.Note: In blockchains, every address implicitly exists with zero balance. You can send coins to any address without it being “created” first.Example:
Account address
Returns the account or a default account with zero balance and nonce
Checks if an account has been explicitly stored.Example:
Account address to check
Balance Operations
Gets an account’s balance.Example:
Nonce Operations
Gets an account’s nonce (transaction counter).Example:
Increments the nonce and returns the old value.Example:
Returns the nonce value before incrementing
Contract Code Storage
Retrieves contract bytecode by its hash.Example:
Hash of the bytecode to retrieve
Contract Storage (SLOAD/SSTORE)
Deletes a key from contract storage.Example:
State Root Computation
Computes the state root from all accounts.Note: This is a naive O(n) implementation that iterates all accounts. Production systems use incremental structures like Merkle Patricia Tries.Example:
Returns a deterministic hash representing the entire state
StorageSlot Type
Complete Example
See Also
- Storage - Low-level database operations
- ChainStore - Block storage and chain management