Skip to content

Supporting packages

These supporting packages provide contract fixtures, chain presets, predeploy helpers, ABI/hex utilities, typed error classes, and remote viem extensions.

Umbrella subpath: tevm/contract (also re-exported from tevm).

  • createContract(params) — build a typed Contract instance (abi, humanReadableAbi, bytecode, deployedBytecode, withAddress(), deploy(), read.*, write.*, events.*) from an ABI or human-readable ABI.
  • Bundled fixtures for tests and examples: SimpleContract, ERC20, ERC721, ErrorContract, AdvancedContract.
  • Types: Contract, CreateContractParams, CreateContractFn, ReadActionCreator, WriteActionCreator, EventActionCreator.
import { createContract, createMemoryClient, PREFUNDED_ACCOUNTS } from 'tevm'
const Counter = createContract({
name: 'Counter',
humanReadableAbi: [
'function count() view returns (uint256)',
'function increment()',
],
})
const bound = Counter.withAddress('0x0000000000000000000000000000000000000123')
console.log(bound.read.count())

See also: contract.tevm.sh.

Umbrella subpath: tevm/common.

  • export * from 'viem/chains' (e.g. mainnet, optimism, base, arbitrum, sepolia, foundry).
  • tevmDefault — alias for foundry (id: 31337).
  • Type: Common (alias for viem’s Chain).
import { mainnet, optimism, tevmDefault } from 'tevm/common'

Umbrella subpath: tevm/predeploys.

  • definePredeploy({ address, contract }) — pair a Contract instance with a fixed deployment address.
  • Types: Predeploy, DefinePredeployFn.

Umbrella subpath: tevm/utils (also re-exported from tevm).

  • Prefunded test accounts: PREFUNDED_ACCOUNTS, PREFUNDED_PRIVATE_KEYS, PREFUNDED_PUBLIC_KEYS, PREFUNDED_SEED.
  • Hardhat console.log decoder: decodeHardhatConsoleLog, HARDHAT_CONSOLE_ADDRESS.
  • Viem & ABI utilities: parseAbi, formatAbi, encodeFunctionData, decodeFunctionResult, encodeDeployData, decodeEventLog, decodeErrorResult, parseEther, formatEther, parseGwei, keccak256, getAddress, isAddress, toHex, fromHex, toBytes, fromBytes, toRlp, fromRlp, hexToBigInt, numberToHex, mnemonicToAccount, signMessage, verifyMessage.

Umbrella subpath: tevm/errors.

Typed BaseError hierarchy covering Ethereum RPC errors (RevertError, ExecutionError, GasLimitExceededError, InsufficientFundsError, NonceTooLowError, NonceTooHighError, InvalidParamsError, MethodNotFoundError, ParseError, InternalError, …), fork errors (ForkError, NoForkUrlSetError, NoForkTransportSetError), and parameter validation errors (InvalidAddressError, InvalidBytecodeError, InvalidAbiError, …).

Standalone package (@tevm/jsonrpc).

  • createJsonRpcFetcher(client) — wrap an EIP-1193 client in a JSON-RPC 2.0 { request } fetcher.
  • loadBalance, rateLimit (from @ponder/utils) and http, webSocket (from viem).
  • Types: JsonRpcClient, JsonRpcRequest, JsonRpcResponse, JsonRpcProcedure, HeadersInit.

Standalone package (@tevm/viem).

  • tevmViemExtension() — viem client decorator adding client.tevm.{ call, contract, deploy, deal, getAccount, setAccount, mine, dumpState, loadState } to any viem client (including remote HTTP/WebSocket clients talking to @tevm/server).
import { createPublicClient, http } from 'viem'
import { tevmViemExtension } from '@tevm/viem'
const client = createPublicClient({
transport: http('http://127.0.0.1:8545'),
}).extend(tevmViemExtension())
const account = await client.tevm.getAccount({
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
})