Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Getting Started with Ethers.js

Tevm's primary client surface is viem-compatible. Ethers v6 can use the same in-memory node through its EIP-1193 provider interface.

Install

npm
npm install tevm@1.0.0-rc.151 viem ethers@6

Create a Provider

createMemoryClient() is synchronous. Its request method follows EIP-1193. Pass the client directly to ethers; Tevm preserves typed RPC return values while also satisfying ethers' open-ended provider interface:

import { createMemoryClient, getAddress } from 'tevm'
import { BrowserProvider, Wallet, formatEther, parseEther } from 'ethers'
 
const client = createMemoryClient()
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'),
})
 
console.log(formatEther(await provider.getBalance(signer.address)))

The negative cache timeout keeps ethers from briefly returning a cached block or balance after Tevm changes local state.

Transactions and Mining

Ethers transactions enter Tevm's txpool. With the default manual mining mode, mine before waiting for the receipt:

const tx = await signer.sendTransaction({
  to: '0x1111111111111111111111111111111111111111',
  value: parseEther('1'),
})
 
await client.mine({ blocks: 1 })
const receipt = await tx.wait()
 
console.log(receipt?.status)

client.mine({ blocks: 1 }) is the viem test action. The equivalent Tevm action is client.tevmMine({ blockCount: 1 }).

See Using with Ethers for a complete contract deployment and write example.