TevmClient
TevmClient:
object
See
guide for more documentation on clients
JSON-RPC
Tevm exposes a JSON-RPC interface for interacting with the EVM via the TevmClient.request
Examples
Actions
TevmClient exposes a higher level actions
based api similar to viem for interacting with TevmClient in a typesasafe
ergonomic way.
Ethereum actions
Ethereum actions are namespaced under TevmClient.eth
Anvil hardhat and ganache compatibility
Will have anvil_* ganache_* and hardhat_* JSON-RPC compatibility in future versions
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
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
dumpState
dumpState:
DumpStateHandler
Dumps the current state of the VM into a JSON-seralizable object
State can be dumped as follows
Examples
And then loaded as follows
eth
eth:
object
Standard JSON-RPC methods for interacting with the VM
See
eth.blockNumber
eth.blockNumber:
EthBlockNumberHandler
Returns the current block number
Set the tag
to a block number or block hash to get the balance at that block
Block tag defaults to ‘pending’ tag which is the optimistic state of the VM
See
Example
eth.call
eth.call:
EthCallHandler
Executes a call without modifying the state
Set the tag
to a block number or block hash to get the balance at that block
Block tag defaults to ‘pending’ tag which is the optimistic state of the VM
See
Example
eth.chainId
eth.chainId:
EthChainIdHandler
Returns the current chain id
Set the tag
to a block number or block hash to get the balance at that block
Block tag defaults to ‘pending’ tag which is the optimistic state of the VM
See
Example
eth.gasPrice
eth.gasPrice:
EthGasPriceHandler
Returns the current gas price
Set the tag
to a block number or block hash to get the balance at that block
Block tag defaults to ‘pending’ tag which is the optimistic state of the VM
See
Example
eth.getBalance
eth.getBalance:
EthGetBalanceHandler
Returns the balance of a given address
Set the tag
to a block number or block hash to get the balance at that block
Block tag defaults to ‘pending’ tag which is the optimistic state of the VM
See
Example
eth.getCode
eth.getCode:
EthGetCodeHandler
Returns code at a given address
Set the tag
to a block number or block hash to get the balance at that block
Block tag defaults to ‘pending’ tag which is the optimistic state of the VM
See
Example
eth.getStorageAt
eth.getStorageAt:
EthGetStorageAtHandler
Returns storage at a given address and slot
Set the tag
to a block number or block hash to get the balance at that block
Block tag defaults to ‘pending’ tag which is the optimistic state of the VM
See
Example
getAccount
getAccount:
GetAccountHandler
Gets the state of a specific ethereum address
Example
loadState
loadState:
LoadStateHandler
Loads a previously dumped state into the VM
State can be dumped as follows
Examples
And then loaded as follows
request
request:
TevmJsonRpcRequestHandler
Request handler for JSON-RPC requests. Most users will want to use the actions
api
instead of this method directly
Example
requestBulk
requestBulk:
TevmJsonRpcBulkRequestHandler
Bulk request handler for JSON-RPC requests. Takes an array of requests and returns an array of results. Bulk requests are currently handled in parallel which can cause issues if the requests are expected to run sequentially or interphere with each other. An option for configuring requests sequentially or in parallel will be added in the future.
Currently is not very generic with regard to input and output types.
Example
tevm_* methods
tevm_call
request - CallJsonRpcRequest response - CallJsonRpcResponse
tevm_getAccount
request - GetAccountJsonRpcRequest response - GetAccountJsonRpcResponse
tevm_setAccount
request - SetAccountJsonRpcRequest response - SetAccountJsonRpcResponse
tevm_fork
request - ForkJsonRpcRequest response - ForkJsonRpcResponse
debug_* methods
debug_traceCall
request - DebugTraceCallJsonRpcRequest response - DebugTraceCallJsonRpcResponse
eth_* methods
eth_blockNumber
request - EthBlockNumberJsonRpcRequest response - EthBlockNumberJsonRpcResponse
eth_chainId
request - EthChainIdJsonRpcRequest response - EthChainIdJsonRpcResponse
eth_getCode
request - EthGetCodeJsonRpcRequest response - EthGetCodeJsonRpcResponse
eth_getStorageAt
request - EthGetStorageAtJsonRpcRequest response - EthGetStorageAtJsonRpcResponse
eth_gasPrice
request - EthGasPriceJsonRpcRequest response - EthGasPriceJsonRpcResponse
eth_getBalance
request - EthGetBalanceJsonRpcRequest response - EthGetBalanceJsonRpcResponse
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
Contract handlers provide a more ergonomic way to execute scripts
setAccount
setAccount:
SetAccountHandler
Sets the state of a specific ethereum address