--- title: Building a Debugger UI description: Build a minimal Svelte EVM debugger with Tevm's opcode hooks and traces --- # Building a Debugger UI This Svelte example runs a real EVM call in the browser and renders its opcode, stack, gas, and trace data. It uses the public `MemoryClient` call API from `tevm@1.0.0-rc.151`; it does not depend on internal VM event emitters. ## Create the App ```bash npm create vite@latest tevm-debugger -- --template svelte-ts cd tevm-debugger npm install npm install tevm@1.0.0-rc.151 viem ``` Replace `src/App.svelte` with the component below. ## Debugger Component ```svelte Tevm Debugger

Tevm EVM Debugger

Execution gas used: {gasUsed.toString()}

{#if error}
{error}
{/if} {#each steps as step} {/each}
PCOpcodeGas leftDepthStack
{step.pc} {step.opcode} {step.gasLeft.toString()} {step.depth} {step.stack.map((value) => `0x${value.toString(16)}`).join(', ') || 'none'}
``` The call executes three instructions, so the table should show `PUSH1`, `PUSH1`, and `SSTORE`. `Array.from(step.stack)` copies each live interpreter stack into stable display data. ## Use the Returned Trace The same call can return a serializable Geth-style trace. It contains `pc`, `op`, `gas`, `gasCost`, `depth`, and stack values for each instruction. ```ts import { createMemoryClient, PREFUNDED_ACCOUNTS } from 'tevm' const client = createMemoryClient() const contract = '0x4444444444444444444444444444444444444444' await client.tevmSetAccount({ address: contract, deployedBytecode: '0x6001600055', }) const result = await client.tevmCall({ from: PREFUNDED_ACCOUNTS[0].address, to: contract, createTrace: true, }) for (const step of result.trace?.structLogs ?? []) { console.log(step.pc, step.op, step.gas, step.stack) } ``` Use the callback for a live UI and the returned trace for export, filtering, comparisons, or persistence. Always call `next?.()` from a callback so execution can continue. ## Next Steps - Add a source map from bytecode offsets to Solidity locations. - Group trace steps by `depth` to visualize nested calls. - Display `step.memory` from the live callback when building a memory inspector. - Persist traces as JSON after converting bigint fields to strings. See [EVM Events](../api/evm-events), [Call API](../api/tevm-call), and [Performance Profiling](../advanced/performance-profiler) for the underlying APIs.