Architecture
TEVM is structured as a thin TypeScript host layer over a native Zig (or WebAssembly) Ethereum node. Every host API — MemoryClient, TevmProvider, @tevm/server, @tevm/mcp, and standalone actions — routes through one serialized boundary: ZevmEngine.
Layer ownership
Section titled “Layer ownership”| Layer | Package / repo | Owns |
|---|---|---|
| EVM interpreter | Guillotine Mini (Zig) | Opcode execution, hardfork rules, gas accounting, debug_traceCall tracer |
| Primitives & state | Voltaire (Zig) | Accounts, bytecode, storage slots, crypto, RLP, precompiles |
| Node runtime | ZEVM (Zig) | NodeRuntime, chain, mempool, mining, receipts, filters, snapshots, fork backend, JSON-RPC router |
| Engine bridge | @tevm/node |
Native Node-API or WASM backend loader, serialized FIFO queue, NativeRpcError, EngineEventEmitter, consoleLog drain |
| Viem client | @tevm/memory-client |
createMemoryClient, createTevmTransport, tevmViemActions (cacheTime: 0) |
| Actions | @tevm/actions |
Browser-safe typed RPC helpers (tevmCall, tevmContract, tevmDeploy, tevmSetAccount, …) |
| Servers | @tevm/server |
HTTP POST/batch, WebSocket subscriptions, Unix IPC framing, Express & Next.js adapters |
Each ZevmEngine owns one isolated backend instance. Two engines never share state unless you explicitly pass the same engine into multiple clients.
The ZevmEngine boundary
Section titled “The ZevmEngine boundary”createZevmEngine(options) (also exported as createTevmNode) wraps either the native Node-API addon, @evmts/zevm/browser WASM reactor, or a custom ZevmBackend with five members:
| Member | Contract |
|---|---|
ready() |
Resolves once initial fork, chain ID, and mining configuration finishes. Rejects and frees backend state if initialization fails. |
request({ method, params }) |
Enqueues one JSON-RPC call, returns the parsed result, or throws NativeRpcError (code, message, optional data). |
rpc(jsonString) |
Enqueues raw JSON-RPC 2.0 wire text (single request, batch array, or notification) and returns the exact response JSON string, or null for notifications. |
events |
Zero-dependency EngineEventEmitter emitting request, response, block, consoleLog, error, and close. |
close() |
Stops the block-poll timer, releases the backend handle, emits close, and removes all listeners. Idempotent. |
Request serialization
Section titled “Request serialization”Callers may invoke request() and rpc() concurrently with Promise.all. Inside ZevmEngine, an internal FIFO promise queue executes every call against the backend strictly one at a time. This guarantees deterministic state transitions without requiring external locks.
Strict backend response validation
Section titled “Strict backend response validation”A backend response must be valid JSON-RPC 2.0 containing exactly one of result or error, and error must carry an integer code and a string message. Malformed responses reject as a transport error rather than a NativeRpcError.
Block observation
Section titled “Block observation”When at least one 'block' listener is registered on engine.events, ZevmEngine checks eth_blockNumber after dispatched calls and on an unreferenced 50 ms timer (at most one poll in flight at a time). Removing all 'block' listeners stops the timer immediately. If more than 64 blocks advance between two polls, only the tip block is emitted.
MemoryClient and the transport boundary
Section titled “MemoryClient and the transport boundary”createMemoryClient(options) builds a viem client with cacheTime: 0 and createTevmTransport(options), then extends it with:
- viem
publicActions(getBlock,getBalance,getLogs,getTransactionReceipt,readContract, …) - viem
walletActions(sendTransaction,writeContract,deployContract, …) - viem
testActions({ mode: 'anvil' })(setBalance,setCode,mine,snapshot,revert,increaseTime, …) tevmViemActions()(tevmReady,tevmClose,tevmCall,tevmContract,tevmDeploy,tevmSetAccount,tevmGetAccount,tevmDeal,tevmMine,tevmDumpState,tevmLoadState)
Every layer dispatches through client.transport.tevm, so state changes made with one surface are immediately visible to all others.
Execution paths
Section titled “Execution paths”- Simulate (
eth_call,tevmCall) — executes against current state (plus optionalstateOverrideorcode), discards state writes, and returnsrawData. Reverts throwNativeRpcErrorwithcode === 3. - Queue (
addToMempool: truewithmining: { auto: false }) — submits viaeth_sendTransaction, leaves the transaction in ZEVM’s txpool, and returns{ rawData: '0x', txHash }. Receipts returnnulluntil mined. - Commit (
addToBlockchain: true, automine, ortevmMine()) — executes pending transactions in Guillotine Mini, updates Voltaire state, appends a canonical block, and indexes receipts and logs.
Resource lifecycle
Section titled “Resource lifecycle”Native and WebAssembly handles live outside JavaScript’s garbage collector. Always release what you create:
MemoryClient:await client.tevmClose()(also closes an externally suppliedengine).ZevmEngine:await engine.close().TevmProvider(@tevm/ethers):provider.destroy().createServer/createIpcServer: close the server first, then callawait client.tevmClose().
Calling request() or rpc() after close() rejects immediately with Error('engine is closed').

