Tutorial: Ethers v6
Run an existing ethers v6 codebase or test suite directly against TEVM without launching a separate JSON-RPC daemon.
You can connect ethers v6 in two ways:
| Approach | Package | Why choose it |
|---|---|---|
TevmProvider (recommended) |
@tevm/ethers |
Subclasses JsonRpcApiProvider, disables ethers’ read cache automatically, routes straight to native rpc(), and exposes provider.tevm for cheatcodes. |
BrowserProvider(client) |
ethers only |
Zero extra packages — wraps createMemoryClient() via EIP-1193. Requires passing { cacheTimeout: -1 }. |
-
Install packages
Section titled “Install packages”Terminal window pnpm add tevm viem ethers@6 @tevm/ethersTerminal window npm install tevm viem ethers@6 @tevm/ethersTerminal window yarn add tevm viem ethers@6 @tevm/ethersTerminal window bun add tevm viem ethers@6 @tevm/ethersOmit
@tevm/ethersif you plan to use ethers’ built-inBrowserProvider. -
Fund a wallet and send a transaction with
Section titled “Fund a wallet and send a transaction with TevmProvider”TevmProviderethers-provider.ts import { TevmProvider } from '@tevm/ethers'import { Wallet, formatEther, parseEther } from 'ethers'import { getAddress } from 'tevm'const provider = await TevmProvider.createMemoryProvider({mining: { auto: false },})try {const signer = Wallet.createRandom().connect(provider)// Use provider.tevm (a full MemoryClient) for local state setupawait provider.tevm.setBalance({address: getAddress(signer.address),value: parseEther('10'),})const balance = await provider.getBalance(signer.address)console.log('Funded balance:', formatEther(balance), 'ETH') // 10.0 ETH// Submit a transaction through ethersconst tx = await signer.sendTransaction({to: '0x1111111111111111111111111111111111111111',value: parseEther('1'),})// Manual mining is enabled, so mine before waiting for the receiptawait provider.tevm.mine({ blocks: 1 })const receipt = await tx.wait()console.log('Receipt status:', receipt?.status) // 1} finally {// Stops ethers polling and closes the underlying ZevmEngineprovider.destroy()} -
Alternative: Wrap
Section titled “Alternative: Wrap MemoryClient with BrowserProvider”MemoryClientwithBrowserProviderIf you prefer not to add
@tevm/ethers, pass aMemoryClientstraight to ethers’BrowserProvider:ethers-browser-provider.ts import { BrowserProvider, Wallet, parseEther } from 'ethers'import { createMemoryClient, getAddress } from 'tevm'const client = createMemoryClient()try {await client.tevmReady()const provider = new BrowserProvider(client, undefined, {cacheTimeout: -1,})const signer = Wallet.createRandom().connect(provider)await client.setBalance({address: getAddress(signer.address),value: parseEther('10'),})// Automining is enabled by default, so tx.wait() resolves immediatelyconst tx = await signer.sendTransaction({to: '0x1111111111111111111111111111111111111111',value: parseEther('1'),})const receipt = await tx.wait()console.log('Mined in block:', receipt?.blockNumber)} finally {await client.tevmClose()}
Next steps
Section titled “Next steps”- Mining & block production — choose between automining, manual mining, and interval mining.
- Accounts, storage & snapshots — manipulate contract state and rewind between tests.
- Ethers package docs — standalone
@tevm/ethersrepository documentation.

