Skip to content

Actions (@tevm/actions)

@tevm/actions (re-exported from tevm and tevm/actions) provides browser-safe, tree-shakeable RPC helpers that operate on any RpcClient ({ request }) — including MemoryClient, ZevmEngine, or a viem client pointing at @tevm/server.

  • tevmCall(client, params: CallParams): Promise<CallResult>
  • tevmContract(client, params): Promise<CallResult & { data?: ReturnType }>
  • tevmDeploy(client, params: DeployParams): Promise<CallResult & { createdAddress?: Address }>
  • tevmDeal(client, params: { address: Address; amount: bigint }): Promise<void>
  • tevmGetAccount(client, params: GetAccountParams): Promise<GetAccountResult>
  • tevmSetAccount(client, params: SetAccountParams): Promise<void>
  • tevmMine(client, params?: MineParams): Promise<void>
  • tevmDumpState(client): Promise<Hex>
  • tevmLoadState(client, state: Hex): Promise<void>
Field Type Description
to Address Destination address. Omit for contract creation or addressless code simulation.
from Address Sender address (defaults to prefunded account 0 when needed).
data Hex Raw calldata (0x...).
value bigint Value to transfer in wei.
gas bigint Gas limit for execution.
gasPrice bigint Legacy gas price in wei.
maxFeePerGas bigint EIP-1559 max fee per gas in wei.
maxPriorityFeePerGas bigint EIP-1559 priority fee in wei.
nonce bigint Explicit transaction nonce.
blockTag string Block tag or hex block number for read calls (default 'latest').
code Hex Runtime bytecode to simulate at to (or zero address if to is omitted).
stateOverride Record<string, JsonValue> Standard eth_call state override object (balance, nonce, code, state, stateDiff).
addToMempool boolean Submit via eth_sendTransaction instead of simulating with eth_call.
addToBlockchain boolean Submit, mine if needed, and require a mined successful receipt. Throws with the transaction hash if pending or reverted.

Returns CallResult: { rawData: Hex; txHash?: Hex; receipt?: JsonValue }.

Extends Omit<CallParams, 'to' | 'data'>:

Field Type Description
bytecode Hex Creation bytecode (required).
abi Abi Optional ABI used to encode constructor args.
args readonly unknown[] Constructor arguments (requires abi).
Field Type Description
address Address Target account address (required).
balance bigint Account balance in wei (anvil_setBalance).
nonce bigint Account nonce (anvil_setNonce).
deployedBytecode Hex Runtime bytecode (anvil_setCode).
storage Record<Hex, Hex> Storage slots and values (up to 32 bytes; left-padded to 32-byte words on the wire).
Field Type Description
blocks number Number of blocks to mine (default 1).
interval number Timestamp spacing in seconds between consecutive mined blocks.

Simulate runtime bytecode without deploying

Section titled “Simulate runtime bytecode without deploying”
import { createMemoryClient } from 'tevm'
const client = createMemoryClient()
try {
// PUSH1 0x2a; PUSH1 0x00; MSTORE; PUSH1 0x20; PUSH1 0x00; RETURN
const { rawData } = await client.tevmCall({
code: '0x602a60005260206000f3',
})
console.log(rawData)
// '0x000000000000000000000000000000000000000000000000000000000000002a'
} finally {
await client.tevmClose()
}
import { createMemoryClient, parseAbi } from 'tevm'
const client = createMemoryClient()
try {
const deployed = await client.tevmDeploy({
bytecode: '0x600a600c600039600a6000f3602a60005260206000f3',
})
const result = await client.tevmContract({
address: deployed.createdAddress!,
abi: parseAbi(['function answer() view returns (uint256)']),
functionName: 'answer',
})
console.log(result.data) // 42n
} finally {
await client.tevmClose()
}
const simulated = await client.tevmCall({
to: '0x0000000000000000000000000000000000000123',
stateOverride: {
'0x0000000000000000000000000000000000000123': {
code: '0x602a60005260206000f3',
},
},
})
console.log(simulated.rawData)
  • Missing createdAddress after tevmDeploy: If mining: { auto: false } and you passed addToMempool: true, the deployment transaction is still pending. Call await client.tevmMine({ blocks: 1 }) or pass addToBlockchain: true.
  • Reverted transaction with addToBlockchain: true: Throws an error carrying the mined txHash so you can inspect the receipt or replay the call with debug_traceCall.