Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Tracing & engine events

Tevm exposes two observability surfaces:

  1. Opcode-level execution traces via native debug_traceCall (executed in Guillotine Mini).
  2. Engine lifecycle events (request, response, block, close) on ZevmEngine.events.

Native opcode tracing (debug_traceCall)

Native Opcode Tracing with debug_traceCall
debug_traceCallcall object + blockTagenableMemory: trueenableReturnData: truedisableStack / StorageGuillotine Mini TracerSnapshots before each opcode:pc · op · gas · gasCost · depthstack[] · memory[] · returnDataCap: 100,000 stepsTrace Payloadgas: 21018failed: falsereturnValue: "0x...2a"truncated: falsestructLogs: [...]
Guillotine Mini records pre-opcode stack, memory, gas, and returnData inside native code and returns a bounded structLogs array.

debug_traceCall runs a call inside Guillotine Mini's native tracer and returns structured pre-opcode execution steps — including failing and reverting calls.

Supported tracer options

OptionTypeDefaultEffect
disableStackbooleanfalseOmit the EVM stack array from each step.
enableMemorybooleanfalseInclude 32-byte memory words before each opcode.
enableReturnDatabooleanfalseInclude the active return-data buffer on each step.
disableStoragebooleantrueOnly true is supported (storage diffs are not recorded per step).

Example: Trace a contract call

import { createMemoryClient } from 'tevm'
 
const client = createMemoryClient()
 
try {
  const target = '0x0000000000000000000000000000000000000123'
  // PUSH1 0x2a; PUSH1 0x00; MSTORE; PUSH1 0x20; PUSH1 0x00; RETURN
  await client.tevmSetAccount({
    address: target,
    deployedBytecode: '0x602a60005260206000f3',
  })
 
  const trace = (await client.transport.tevm.request({
    method: 'debug_traceCall',
    params: [
      { to: target },
      'latest',
      { enableMemory: true, enableReturnData: true },
    ],
  })) as {
    gas: number
    failed: boolean
    returnValue: string
    truncated: boolean
    structLogs: Array<{
      pc: number
      op: string
      gas: number
      gasCost: number
      depth: number
      stack: string[]
      memory?: string[]
      returnData?: string
    }>
  }
 
  console.log({
    gas: trace.gas,
    failed: trace.failed,
    returnValue: trace.returnValue,
    truncated: trace.truncated,
    opcodes: trace.structLogs.map((s) => `${s.pc}:${s.op}(-${s.gasCost})`),
  })
  // opcodes: ['0:PUSH1(-3)', '2:PUSH1(-3)', '4:MSTORE(-6)', '5:PUSH1(-3)', '7:PUSH1(-3)', '9:RETURN(-0)']
} finally {
  await client.tevmClose()
}

Trace payload fields

FieldTypeDescription
gasnumberTotal gas used by the traced call (including intrinsic gas).
failedbooleantrue if the call reverted or hit an EVM exception.
returnValueHexRaw return data (or revert payload when failed is true).
truncatedbooleantrue if execution exceeded the 100,000-step native retention cap.
structLogsArray<StructLog>Per-opcode trace entries (pc, op, gas, gasCost, depth, stack, optional memory, optional returnData).

Engine lifecycle events (engine.events)

Access the engine's EventEmitter via client.transport.tevm.events (or engine.events when using createZevmEngine):

import { createMemoryClient } from 'tevm'
 
const client = createMemoryClient({ mining: { auto: false } })
const { events } = client.transport.tevm
 
events.on('request', (req) => console.log('->', req.method))
events.on('response', ({ request }) => console.log('<-', request.method))
events.on('block', (block) => console.log('block mined:', block.number))
events.on('close', () => console.log('engine closed'))
 
try {
  await client.tevmMine({ blocks: 1 })
} finally {
  await client.tevmClose()
}
EventFires when
requestBefore engine.request() dispatches to ZEVM.
responseAfter engine.request() resolves.
blockWhenever chain height advances — including autonomous blocks mined on the native interval thread.
closeOnce when tevmClose() / engine.close() frees the native handle.

Next: Browser trace viewer cookbook · Engine API · MCP server