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

TevmNode Interface

TevmNode owns Tevm's stateful runtime. Most applications should use createMemoryClient; use the node directly when building decorators, servers, or execution tooling.

Create and Initialize a Node

import { createTevmNode } from 'tevm'
 
const node = createTevmNode({
  miningConfig: { type: 'manual' },
})
 
console.log(node.mode, node.miningConfig)
await node.ready()

createTevmNode() is synchronous. ready() eagerly completes the lazy VM, chain, state, txpool, and receipt initialization.

Component Access

import { createTevmNode } from 'tevm'
 
const node = createTevmNode()
const vm = await node.getVm()
const txPool = await node.getTxPool()
const receipts = await node.getReceiptsManager()
const head = await vm.blockchain.getCanonicalHeadBlock()
 
console.log({
  blockNumber: head.header.number,
  pooledSenders: txPool.pool.size,
  maximumLogs: receipts.GET_LOGS_LIMIT,
})

These objects use low-level Ethereum types. Prefer public actions for normal account, block, transaction, receipt, and log queries.

Add APIs with Decorators

The base node does not expose request. Add the EIP-1193 decorator explicitly:

import { createTevmNode } from 'tevm'
import { requestEip1193, tevmActions } from 'tevm/decorators'
 
const node = createTevmNode()
  .extend(tevmActions())
  .extend(requestEip1193())
 
const chainId = await node.request({ method: 'eth_chainId' })
const account = await node.getAccount({
  address: '0x1111111111111111111111111111111111111111',
})
 
console.log(chainId, account.balance)

Other built-in decorators include ethActions and tevmSend. Decorators return an extended node and share the original node's state.

Runtime Controls

import { createTevmNode } from 'tevm'
 
const node = createTevmNode()
 
node.setMiningConfig({ type: 'interval', blockTime: 5 })
node.setNextBlockTimestamp(2_000_000_000n)
node.setNextBlockGasLimit(30_000_000n)
node.setTracesEnabled(true)
node.setAutoImpersonate(true)
 
node.setMiningConfig({ type: 'manual' })
await node.close()

close() stops interval mining and releases node resources.

Extend with Application Logic

import { createTevmNode } from 'tevm'
 
const node = createTevmNode().extend((baseNode) => ({
  async getHeadNumber() {
    const vm = await baseNode.getVm()
    const head = await vm.blockchain.getCanonicalHeadBlock()
    return head.header.number
  },
}))
 
console.log(await node.getHeadNumber())

Keep extensions thin and compose existing node methods. Use the handler factories in tevm/actions when an extension needs Tevm or JSON-RPC behavior.

Related

Architecture Overview · Memory Client · Decorators