Actions
Overview
Tevm has an actions based api similar to viem’s actions api and following similar patterns. This is a higher level of abstraction than the lower level JSON-RPC api
Errors
All actions return errors as values
const {errors} = client.setAccount({})if (errors?.length) { console.log(errors[0]).name // AddressRequiredError console.log(errors[0].message) // AddressRequiredError: `address` is a required property}
As a best practice you should always check the errors property for errors. In future versions of tevm we may expose the ability to throw instead as a configuration option to the client. Consider joining the telegram if you would like this feature.
TevmClient actions
TevmClient methods are the main recomended way to interact with Tevm. 🚧 means the procedure is still under construction
TevmClient.call
- Similar to eth call but with additional properties to control the VM executionTevmClient.getAccount
- gets account information such as balances contract information nonces and state roots.TevmClient.setAccount
- directly modifies the state of an accountTevmClient.contract
- Similar to eth call but with additional properties to control the VM executionTevmClient.script
- Runs the provided bytecode against the EVM state- 🚧
TevmClient.traceContractCall
- 🚧
TevmClient.traceScript
TevmClient.dumpState
- Returns the state of the VMTevmClient.loadState
- Initializes the state of the VM
Note the call
family of actions including TevmClient.call
, TevmClient.contract
, and TevmClient.script
will execute in a sandbox and not modify the state. This behavior can be disabled via passing in a enableTransaction: true
parameter.
Eth methods
TevmClient plans on implementing most of the ethereum JSON-RPC spec
- `TevmClient.eth.accounts’ - Uses the same test accounts ganache anvil and hardhat uses. Mnemonic: test test test test test test test test test test test junk
- `TevmClient.eth.call’
- `TevmClient.eth.chainId’
- `TevmClient.eth.estimateGas’
- `TevmClient.eth.gasPrice’
- `TevmClient.eth.getBalance’
- `TevmClient.eth.getCode’
- `TevmClient.eth.getStorageAt’
- `TevmClient.eth.sign’
- `TevmClient.eth.signTransaction’
- 🚧 `TevmClient.eth.getLogs’
- 🚧 `TevmClient.eth.coinbase’
- 🚧 `TevmClient.eth.hashrate’
- 🚧 `TevmClient.eth.newFilter’
- 🚧 `TevmClient.eth.getFilterLogs’
- 🚧 `TevmClient.eth.getBlockByHash’
- 🚧 `TevmClient.eth.newBlockFilter’
- 🚧 `TevmClient.eth.protocolVersion’
- 🚧 `TevmClient.eth.sendTransaction’
- 🚧 `TevmClient.eth.uninstallFilter’
- 🚧 `TevmClient.eth.getBlockByNumber’
- 🚧 `TevmClient.eth.getFilterChanges’
- 🚧 `TevmClient.eth.sendRawTransaction’
- 🚧 `TevmClient.eth.getTransactionCount’
- 🚧 `TevmClient.eth.getTransactionByHash’
- 🚧 `TevmClient.eth.getTransactionReceipt’
- 🚧 `TevmClient.eth.newPendingTransactionFilter’
- 🚧 `TevmClient.eth.getBlockTransactionCountByHash’
- 🚧 `TevmClient.eth.getBlockTransactionCountByNumber’
- 🚧 `TevmClient.eth.getTransactionByBlockHashAndIndex’
- 🚧 `TevmClient.eth.getTransactionByBlockNumberAndIndex’
Debug methods
Anvil/Hardhat methods
Anvil/hardhat methods are provided for compatability
- 🚧 `TevmClient.anvil.mine’
- 🚧 `TevmClient.anvil.reset’
- 🚧 `TevmClient.anvil.setCode’
- 🚧 `TevmClient.anvil.setNonce’
- 🚧 `TevmClient.anvil.dumpState’
- 🚧 `TevmClient.anvil.loadState’
- 🚧 `TevmClient.anvil.setBalance’
- 🚧 `TevmClient.anvil.setChainId’
- 🚧 `TevmClient.anvil.getAutomine’
- 🚧 `TevmClient.anvil.setStorageAt’
- 🚧 `TevmClient.anvil.dropTransaction’
- 🚧 `TevmClient.anvil.impersonateAccount’
- 🚧 `TevmClient.anvil.stopImpersonatingAccount’
Tree shakeable actions
Like viem, TevmClient provides tree shakable versions of the actions in the tevm/procedures package. But for Tevm it is recomended you use the higher level client apis. If bundle size is a concern a more effective way of reducing bundle size is using a remote http client and running the EVM on a backend server