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

Virtual Machine

@tevm/vm coordinates the EVM, state manager, blockchain, block building, and transaction execution. Most applications should use createMemoryClient; direct VM access is intended for runtime integrations.

Access the Configured VM

import { createTevmNode } from 'tevm'
import { createAddress } from 'tevm/address'
import { createImpersonatedTx } from 'tevm/tx'
 
const node = createTevmNode()
const vm = await node.getVm()
 
const tx = createImpersonatedTx({
  impersonatedAddress: createAddress(
    '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  ),
  to: createAddress('0x1111111111111111111111111111111111111111'),
  value: 1n,
  gasLimit: 21_000n,
  maxFeePerGas: 10n,
  maxPriorityFeePerGas: 1n,
})
 
const result = await vm.runTx({ tx })
console.log(result.totalGasSpent, result.execResult.returnValue)

The node constructs compatible common, stateManager, blockchain, evm, txpool, and receipt components. Prefer this over assembling a partial VM unless you are implementing a custom runtime.

Important VM Methods

  • runTx executes a typed transaction.
  • runBlock executes and validates a block.
  • buildBlock creates a block builder.
  • deepCopy creates an isolated runtime copy.
  • stateManager, blockchain, and evm expose the configured subcomponents.

Direct execution follows checkpoint and hardfork rules. For simulations with Tevm error handling, tracing, overrides, and ABI decoding, use client.tevmCall or client.tevmContract.

Related

TevmNode Interface · EVM · State · Blockchain