Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 1.78 KB

File metadata and controls

62 lines (42 loc) · 1.78 KB

@tevm/actions


@tevm/actions / setAccountHandler

Function: setAccountHandler()

setAccountHandler(client, options?): SetAccountHandler

Defined in: packages/actions/src/SetAccount/setAccountHandler.js:47

Creates a handler for setting account state in the Ethereum Virtual Machine

This handler allows you to completely modify an account's state, including:

  • Setting account balance and nonce
  • Deploying contract bytecode
  • Modifying contract storage
  • Setting storage roots directly

It's particularly useful for test environments where you need to set up specific contract states or account balances before running tests.

Use state to overwrite the account's storage (clears existing slots first) or stateDiff to patch individual slots without clearing.

Parameters

Parameter Type Description
client TevmNode<"fork" | "normal", { }> -
options? { throwOnFail?: boolean; } -
options.throwOnFail? boolean -

Returns

SetAccountHandler

Throws

When validation fails and throwOnFail is true.

Throws

When putting account state fails and throwOnFail is true.

Example

import { createTevmNode } from '@tevm/node'
import { setAccountHandler } from '@tevm/actions'
import { parseEther } from 'viem'

const handler = setAccountHandler(createTevmNode())
await handler({
  address: '0x1234567890123456789012345678901234567890',
  balance: parseEther('1000'),
  nonce: 5n,
  deployedBytecode: '0x6080...',
  stateDiff: { '0x00...00': '0x00...05' },
})