Quickstart
Embed an isolated Ethereum node directly inside your TypeScript or JavaScript process — no Docker container, background Anvil process, or port management required.
By the end of this tutorial, you will have run a local ETH transfer, deployed and called contract bytecode, caught a structured revert error, and forked an upstream network at a pinned block.
Prerequisites
Section titled “Prerequisites”- Node.js 22.12 or later (Node.js 24 is tested in CI) for the native Node-API addon, or a modern browser/bundler for WebAssembly execution.
- A package manager (
pnpm,npm,yarn, orbun).
-
Install TEVM and viem
Section titled “Install TEVM and viem”Terminal window pnpm add tevm viemTerminal window npm install tevm viemTerminal window yarn add tevm viemTerminal window bun add tevm viem -
Send ETH and mine a block
Section titled “Send ETH and mine a block”Create
quickstart.mjsand run it withnode quickstart.mjs:quickstart.mjs import { createMemoryClient, parseEther, PREFUNDED_ACCOUNTS } from 'tevm'const client = createMemoryClient({mining: { auto: false },})try {const sender = PREFUNDED_ACCOUNTS[0].addressconst recipient = '0x1111111111111111111111111111111111111111'// Queue a transfer in the mempool without mining yetconst { txHash } = await client.tevmCall({from: sender,to: recipient,value: parseEther('1'),addToMempool: true,})// Commit the pending transaction into block 1await client.tevmMine({ blocks: 1 })// Query the receipt and updated balance using standard viem actionsconst receipt = await client.getTransactionReceipt({ hash: txHash })const balance = await client.getBalance({ address: recipient })console.log({ status: receipt.status, balance })} finally {// Always release the native ZEVM handle when finishedawait client.tevmClose()}Expected output:
{ status: 'success', balance: 1000000000000000000n }Here is what happened:
createMemoryClient({ mining: { auto: false } })created an isolated ZEVM chain with chain ID31337, block height0, and 10 prefunded accounts holding 10,000 ETH each.tevmCall({ ..., addToMempool: true })submitted the transfer viaeth_sendTransactionand returned itstxHash.tevmMine({ blocks: 1 })rananvil_mine, committed the state transition, and indexed the receipt.tevmClose()freed the native engine handle.
-
Deploy bytecode and call a contract
Section titled “Deploy bytecode and call a contract”Use
tevmDeployto deploy creation bytecode andtevmContractfor ABI-typed reads and writes:deploy.mjs import { createMemoryClient, parseAbi } from 'tevm'const client = createMemoryClient()try {// Minimal creation bytecode deploying a contract that returns uint256(42)const deployed = await client.tevmDeploy({bytecode: '0x600a600c600039600a6000f3602a60005260206000f3',})const result = await client.tevmContract({address: deployed.createdAddress,abi: parseAbi(['function answer() view returns (uint256)']),functionName: 'answer',})console.log('Deployed at:', deployed.createdAddress)console.log('answer() =>', result.data)} finally {await client.tevmClose()}Expected output:
Deployed at: 0x5fbdb2315678afecb367f032d93f642f64180aa3answer() => 42n -
Handle an EVM revert
Section titled “Handle an EVM revert”When a call reverts, TEVM throws a
NativeRpcErrorwith JSON-RPC error code3and the raw revert payload onerror.data:revert.mjs import { createMemoryClient, NativeRpcError } from 'tevm'const client = createMemoryClient()try {// Runtime bytecode: PUSH1 0x00; PUSH1 0x00; REVERTawait client.tevmCall({ code: '0x60006000fd' })} catch (error) {if (error instanceof NativeRpcError) {console.log({ code: error.code, message: error.message, data: error.data })// { code: 3, message: 'execution reverted', data: '0x' }} else {throw error}} finally {await client.tevmClose()} -
Fork an upstream chain
Section titled “Fork an upstream chain”Pass
fork.urland pinfork.blockNumberfor deterministic reads against live mainnet state. Missing accounts, code, and storage load lazily on cache miss while local writes stay in-process:fork.mjs import { createMemoryClient } from 'tevm'import { mainnet } from 'tevm/common'const client = createMemoryClient({chainId: mainnet.id,common: mainnet,fork: {url: 'https://ethereum-rpc.publicnode.com',blockNumber: 20_000_000,},})try {await client.tevmReady()const vitalik = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'const balance = await client.getBalance({ address: vitalik })console.log('Forked balance:', balance)// Mutate locally — never touches mainnetawait client.tevmDeal({ address: vitalik, amount: balance + 1n })console.log('Local balance:', await client.getBalance({ address: vitalik }))} finally {await client.tevmClose()}
Next steps
Section titled “Next steps”- Browsers & WebAssembly — run TEVM inside browsers, Web Workers, and edge runtimes.
- Tutorial: Viem — use viem public, wallet, and test actions or build a tree-shakeable client.
- Tutorial: Ethers v6 — connect an ethers v6 codebase with
TevmProvider. - Tutorial: Solidity bundler — import
.solfiles directly as typed TypeScript modules. - Architecture — learn how
MemoryClient,ZevmEngine, ZEVM, Voltaire, and Guillotine Mini divide ownership.

