Memory client (@tevm/memory-client)
@tevm/memory-client (re-exported from tevm and tevm/memory-client) creates a viem v2 client backed by an in-process ZevmEngine.
Reference
Section titled “Reference”Exports
Section titled “Exports”createMemoryClient(options?: MemoryClientOptions): MemoryClientcreateTevmTransport(options?: ZevmEngineOptions & { engine?: ZevmEngine }): TransporttevmViemActions()— viem client decorator attachingtevmReady,tevmClose,tevmCall,tevmContract,tevmDeploy,tevmDeal,tevmGetAccount,tevmSetAccount,tevmMine,tevmDumpState,tevmLoadStatetevmReady(client): Promise<void>- Action re-exports from
@tevm/actions:tevmCall,tevmContract,tevmDeal,tevmDeploy,tevmDumpState,tevmGetAccount,tevmLoadState,tevmMine,tevmSetAccount - Viem re-exports:
createClient,publicActions,walletActions,testActions
MemoryClientOptions
Section titled “MemoryClientOptions”Extends ZevmEngineOptions:
| Option | Type | Default | Description |
|---|---|---|---|
chainId |
number |
common?.id ?? 31337 |
Unsigned safe integer chain ID. Throws if it disagrees with common.id. |
common |
Chain (viem) |
foundry (with chainId) |
Viem Chain metadata attached as client.chain. With an injected backend or engine and neither common nor chainId, client.chain is undefined. |
mining |
{ auto?: boolean; interval?: number } |
{ auto: true } |
Automine flag and optional background interval in whole seconds (0 disables timer). |
fork |
{ url: string; blockNumber?: number } |
undefined |
Upstream JSON-RPC endpoint and optional pinned block number (unsigned safe integer). |
backend |
ZevmBackend |
undefined |
Custom { rpc, close } JSON-RPC backend. Mutually exclusive with wasm. |
wasm |
boolean | ZevmWasmSource |
auto outside Node.js | Force (true / bytes / WebAssembly.Module) or disable (false) @evmts/zevm/browser WASM reactor. Mutually exclusive with backend. |
consoleLog |
boolean | ConsoleLogHandler |
false |
Capture Hardhat Solidity console.log calls. Ignored when engine is supplied directly. |
engine |
ZevmEngine |
new engine | Supply an existing ZevmEngine. client.tevmClose() still closes it. |
account |
Account | Hex |
undefined |
Default account for viem wallet actions (sendTransaction, writeContract, deployContract). |
name |
string |
'TEVM' |
Viem client display name. |
key |
string |
'tevm' |
Viem client key. |
Client methods map
Section titled “Client methods map”A MemoryClient exposes five namespaces on one object:
| Surface | Key methods |
|---|---|
| Lifecycle | tevmReady(), tevmClose(), transport.tevm (ZevmEngine) |
| TEVM actions | tevmCall, tevmContract, tevmDeploy, tevmDeal, tevmGetAccount, tevmSetAccount, tevmMine, tevmDumpState, tevmLoadState |
| Viem public | getBlockNumber, getBlock, getBalance, getCode, getStorageAt, getTransaction, getTransactionReceipt, getLogs, readContract, simulateContract, call, estimateGas, multicall |
| Viem wallet | sendTransaction, writeContract, deployContract, signMessage, signTypedData |
| Viem test (Anvil) | mine, setBalance, setCode, setNonce, setStorageAt, impersonateAccount, stopImpersonatingAccount, snapshot, revert, increaseTime, setNextBlockTimestamp, setAutomine, getAutomine, setIntervalMining, dumpState, loadState |
Initialize with explicit chain metadata and default account
Section titled “Initialize with explicit chain metadata and default account”import { createMemoryClient, PREFUNDED_ACCOUNTS } from 'tevm'import { optimism } from 'tevm/common'
const client = createMemoryClient({ chainId: optimism.id, common: optimism, account: PREFUNDED_ACCOUNTS[0],})
try { await client.tevmReady() console.log(await client.getChainId()) // 10} finally { await client.tevmClose()}Share an existing ZevmEngine
Section titled “Share an existing ZevmEngine”import { createMemoryClient, createZevmEngine } from 'tevm'
const engine = createZevmEngine({ mining: { auto: false } })const client = createMemoryClient({ engine })
try { await client.tevmReady() console.log(await client.getBlockNumber()) // 0n} finally { // Also closes `engine` await client.tevmClose()}Troubleshooting
Section titled “Troubleshooting”- Synchronous
TypeErroron construction:chainId,mining.interval, andfork.blockNumbermust be unsigned safe integers (Number.isSafeInteger(v) && v >= 0). Passing floats, negative numbers, or achainIdthat differs fromcommon.idthrows immediately. - Viem action throws
MethodNotFound(-32601):createMemoryClientattaches viem’s full public, wallet, and Anvil action sets, but exact RPC method support is governed by ZEVM. See JSON-RPC reference. - Process hangs on exit: You left an open client (especially with interval mining enabled) or an active
'block'listener without callingawait client.tevmClose().

