TevmActionsApi
TevmActionsApi:
object
The actions api is the high level API for interacting with a Tevm client similar to viem actions
See
https://tevm.sh/learn/actions/
Type declaration
call
call:
CallHandler
Executes a call against the VM. It is similar to eth_call
but has more
options for controlling the execution environment
By default it does not modify the state after the call is complete but this can be configured.
Example
const res = tevm.call({ to: '0x123...', data: '0x123...', from: '0x123...', gas: 1000000, gasPrice: 1n, skipBalance: true,}
contract
contract:
ContractHandler
Executes a contract call against the VM. It is similar to eth_call
but has more
options for controlling the execution environment along with a typesafe API
for creating the call via the contract abi.
The contract must already be deployed. Otherwise see script
which executes calls
against undeployed contracts
Example
const res = await tevm.contract({ to: '0x123...', abi: [...], function: 'run', args: ['world'] from: '0x123...', gas: 1000000, gasPrice: 1n, skipBalance: true,}console.log(res.data) // "hello"
deploy
deploy:
DeployHandler
Creates a transaction to deploys a contract to tevm
dumpState
dumpState:
DumpStateHandler
Dumps the current state of the VM into a JSON-seralizable object
State can be dumped as follows
Examples
const {state} = await tevm.dumpState()fs.writeFileSync('state.json', JSON.stringify(state))
And then loaded as follows
const state = JSON.parse(fs.readFileSync('state.json'))await tevm.loadState({state})
getAccount
getAccount:
GetAccountHandler
Gets the state of a specific ethereum address
Example
const res = tevm.getAccount({address: '0x123...'})console.log(res.deployedBytecode)console.log(res.nonce)console.log(res.balance)
loadState
loadState:
LoadStateHandler
Loads a previously dumped state into the VM
State can be dumped as follows
Examples
const {state} = await tevm.dumpState()fs.writeFileSync('state.json', JSON.stringify(state))
And then loaded as follows
const state = JSON.parse(fs.readFileSync('state.json'))await tevm.loadState({state})
mine
mine:
MineHandler
Mines 1 or more blocks
script
script:
ScriptHandler
Executes scripts against the Tevm EVM. By default the script is sandboxed
and the state is reset after each execution unless the persist
option is set
to true.
Examples
const res = tevm.script({ deployedBytecode: '0x6080604...', abi: [...], function: 'run', args: ['hello world']})
Contract handlers provide a more ergonomic way to execute scripts
ipmort {MyScript} from './MyScript.s.sol'
const res = tevm.script( MyScript.read.run('hello world'))
setAccount
setAccount:
SetAccountHandler
Sets the state of a specific ethereum address
Example
import {parseEther} from 'tevm'
await tevm.setAccount({ address: '0x123...', deployedBytecode: '0x6080604...', balance: parseEther('1.0')})