Mining & block production
TEVM supports three block-production modes controlled by ZEVM’s native miner: automining (default), manual mining, and interval mining.
| Mode | Configuration | When blocks are produced | Best for |
|---|---|---|---|
| Automine (default) | { mining: { auto: true } } or omitted |
Immediately after each submitted transaction | Fast scripts, simple unit tests, interactive flows |
| Manual | { mining: { auto: false } } |
Only when you call tevmMine(), client.mine(), or evm_mine |
Batching multiple transactions in one block, txpool inspection |
| Interval | { mining: { auto: false, interval: 2 } } |
Automatically every N whole seconds on a background Zig thread |
Local dev servers simulating live block cadence |
Manual mining and txpool batching
Section titled “Manual mining and txpool batching”Disable automining to queue multiple transactions in the mempool and commit them into one block:
import { createMemoryClient, parseEther, PREFUNDED_ACCOUNTS } from 'tevm'
const [alice, bob, charlie] = PREFUNDED_ACCOUNTSconst client = createMemoryClient({ mining: { auto: false },})
try { const tx1 = await client.tevmCall({ from: alice.address, to: bob.address, value: parseEther('1'), addToMempool: true, }) const tx2 = await client.tevmCall({ from: alice.address, to: charlie.address, value: parseEther('2'), addToMempool: true, })
// Neither receipt exists before mining console.log(await client.request({ method: 'eth_getTransactionReceipt', params: [tx1.txHash!] })) // null
// Mine 1 block containing both pending transactions await client.tevmMine({ blocks: 1 })
const block = await client.getBlock({ blockNumber: 1n }) console.log('Mined tx count:', block.transactions.length) // 2 console.log('Hashes:', [tx1.txHash, tx2.txHash])} finally { await client.tevmClose()}Mine multiple blocks with timestamp spacing
Section titled “Mine multiple blocks with timestamp spacing”Pass blocks and interval (seconds between consecutive blocks) to tevmMine:
// Mine 5 blocks spaced 12 seconds apartawait client.tevmMine({ blocks: 5, interval: 12 })To advance time explicitly before the next block, use viem’s Anvil test actions (increaseTime / setNextBlockTimestamp):
// Jump 1 hour forward, then mine 1 blockawait client.increaseTime({ seconds: 3600 })await client.tevmMine({ blocks: 1 })
// Or pin the exact Unix timestamp of the next blockawait client.setNextBlockTimestamp({ timestamp: 1_800_000_000n })await client.tevmMine({ blocks: 1 })Interval mining and observing new blocks
Section titled “Interval mining and observing new blocks”Set mining: { auto: false, interval: 2 } to mine a block every 2 seconds on ZEVM’s background thread. Attach a 'block' listener on client.transport.tevm.events to react whenever chain height advances:
import { createMemoryClient } from 'tevm'
const client = createMemoryClient({ mining: { auto: false, interval: 2 },})
try { await client.tevmReady()
await new Promise<void>((resolve) => { client.transport.tevm.events.on('block', (block) => { console.log('Observed block:', (block as { number: string }).number) resolve() }) })} finally { // Stops the background interval thread and releases native state await client.tevmClose()}Toggle mining mode at runtime
Section titled “Toggle mining mode at runtime”Switch modes on a running client via standard Anvil/EVM JSON-RPC methods:
// Turn automining off at runtimeawait client.setAutomine(false)
// Check current automine stateconst isAuto = await client.getAutomine()
// Enable 3-second interval mining (pass 0 to stop)await client.setIntervalMining({ interval: 3 })Next steps
Section titled “Next steps”- Accounts, storage & snapshots — mutate balances and storage, or rewind blocks with
snapshot()/revert(). - Tracing, console.log & events — subscribe to all
ZevmEngine.eventsnotifications. - Memory client reference — full option validation rules.

