@tevm/evm
Tevm's low-level EVM facade. Backed by @evmts/zevm/evm and wrapped with Tevm-specific defaults for state, blockchain, precompiles, predeploys, logging, profiling, and unlimited-contract-size testing.
Most apps should use createMemoryClient, viem actions, or JSON-RPC. Use @tevm/evm directly when building Tevm extensions, debuggers, or profilers.
Full API: packages/evm/docs.
Installation
npm install @tevm/evmAPI Reference
- Evm - EVM facade.
- createEvm - creates an EVM for a Tevm VM.
- CreateEvmOptions
- CustomPrecompile
- EVMOpts - ZEVM EVM options exposed through Tevm.
- Re-exported ZEVM EVM types:
EvmError,EVMError,EvmResult,EvmRunCallOpts,ExecResult,InterpreterStep,Log,EthjsMessage,PrecompileInput.
Usage Examples
import { createChain } from '@tevm/blockchain'
import { mainnet } from '@tevm/common'
import { createEvm } from '@tevm/evm'
import { createStateManager } from '@tevm/state'
import { createAddress } from '@tevm/address'
const common = mainnet.copy()
const stateManager = createStateManager({ common })
const blockchain = await createChain({ common })
const evm = await createEvm({
common,
stateManager,
blockchain,
profiler: false,
loggingLevel: 'warn',
})
const result = await evm.runCall({
to: createAddress('0x1234567890123456789012345678901234567890'),
caller: createAddress('0x5678901234567890123456789012345678901234'),
data: new Uint8Array(),
value: 1000n,
gasLimit: 100000n,
})
evm.events?.on('step', (step) => {
console.log({ pc: step.pc, opcode: step.opcode.name, gasLeft: step.gasLeft, depth: step.depth })
})Custom Precompiles
import { createContract, createMemoryClient, defineCall, definePrecompile, parseAbi } from 'tevm'
const Calculator = createContract({
name: 'Calculator',
address: '0x0000000000000000000000000000000000000a11',
abi: parseAbi(['function addTwo(uint256 value) returns (uint256)']),
})
const calculatorPrecompile = definePrecompile({
contract: Calculator,
call: defineCall(Calculator.abi, {
addTwo: async ({ args }) => ({ returnValue: args[0] + 2n, executionGasUsed: 0n }),
}),
})
const client = createMemoryClient({
customPrecompiles: [calculatorPrecompile.precompile()],
})
