@tevm/memory-client
In-memory Ethereum client combining viem with Tevm's EVM. Supports forking, manual/auto mining, and Tevm-specific actions on top of standard viem public, wallet, and test actions.
Installation
npm install @tevm/memory-clientAPI Reference
Type Aliases
- CreateMemoryClientFn
- MemoryClient
- MemoryClientOptions
- TevmActions
- TevmContract
- TevmRpcSchema
- TevmTransport
- TevmViemActionsApi
Actions
- createClient
- createMemoryClient
- createTevmTransport
- publicActions
- testActions
- tevmCall
- tevmContract
- tevmDeal - add native ETH or ERC20 tokens.
- tevmDeploy
- tevmDumpState
- tevmGetAccount
- tevmLoadState
- tevmMine
- tevmReady
- tevmSetAccount
- tevmViemActions
- walletActions
Client Options
interface MemoryClientOptions<TCommon, TAccountOrAddress, TRpcSchema> {
common?: TCommon
fork?: {
transport: Transport
blockTag?: string | number
}
name?: string
account?: TAccountOrAddress
pollingInterval?: number
cacheTime?: number
}Usage Examples
import { createMemoryClient, http, PREFUNDED_ACCOUNTS } from 'tevm'
import { optimism } from 'tevm/common'
const rpcUrl = process.env.OPTIMISM_RPC_URL
if (!rpcUrl) {
throw new Error('OPTIMISM_RPC_URL is required for fork mode')
}
const client = createMemoryClient({
fork: {
transport: http(rpcUrl)({}),
blockTag: 'latest',
},
common: optimism,
})
const manualMining = createMemoryClient({
miningConfig: { type: 'manual' },
account: PREFUNDED_ACCOUNTS[0],
})
await manualMining.mine({ blocks: 1 })
await client.setAccount({
address: '0x1234567890123456789012345678901234567890',
balance: 100n,
nonce: 1n,
state: {
'0x0000000000000000000000000000000000000000000000000000000000000000':
'0x0000000000000000000000000000000000000000000000000000000000000001',
},
})
const account = await client.getAccount({
address: '0x1234567890123456789012345678901234567890',
returnStorage: true,
})
const deployResult = await client.tevmDeploy({
abi: contractAbi,
bytecode: contractBytecode,
args: ['Constructor', 'Args'],
})
const callResult = await client.tevmCall({
to: contractAddress,
data: encodeFunctionData(/* ... */),
})
const contractResult = await client.tevmContract({
contract: myContract,
method: 'myMethod',
args: [arg1, arg2],
})
const hash = await client.writeContract({
address: contractAddress,
abi: contractAbi,
functionName: 'myFunction',
args: [arg1, arg2],
})
const receipt = await client.waitForTransactionReceipt({ hash })State Persistence
import { createMemoryClient, createSyncPersister } from '@tevm/memory-client'
const client = createMemoryClient({
persister: createSyncPersister({ storage: localStorage }),
})HTTP Server Integration
import { createServer } from '@tevm/server'
import { createMemoryClient } from '@tevm/memory-client'
const server = createServer({ request: createMemoryClient().request })
server.listen(8545)Network Support
Officially supported: Ethereum mainnet, standard OP Stack chains. Other EVM chains may work but aren't officially supported.
EIP Support
Always enabled: EIP-1559, EIP-4895, EIP-4844, EIP-4788.

