Database
Database
Section titled “Database”zevm.database combines journaled account state with account and contract-code stores used by block execution. Reach for it when embedding ZEVM execution and you need owned in-memory state or a Merkle account root.
Working example
Section titled “Working example”This complete Zig program was run with the repository exposed as the zevm build module.
const std = @import("std");const zevm = @import("zevm");
pub fn main() !void { var debug_allocator: std.heap.DebugAllocator(.{}) = .init; defer _ = debug_allocator.deinit(); const allocator = debug_allocator.allocator();
var db = try zevm.database.Database.init(allocator, null); defer db.deinit(allocator);
if (db.accounts.stateRoot() != null) return error.ExpectedEmptyDatabase; std.debug.print("state_root=null\n", .{});}zig build run-databasestate_root=nullThe public declarations come from database/root.zig, database.zig, accounts.zig, and contracts.zig.
| Type | Members |
|---|---|
Database |
init, deinit, syncAccountToTrie, syncCachedAccountsToTrie, plus state, accounts, and contracts |
Accounts |
init, deinit, get, put, remove, stateRoot |
Contracts |
init, deinit, get, put, remove |
StateManager is the account-state source of truth. Call a sync method before reading the account trie root after state mutations.
Neighbours
Section titled “Neighbours”Execution library · Genesis and chain import · State, fork, and snapshots