@tevm/actions
The @tevm/actions
package provides a comprehensive set of actions for interacting with the Tevm client. It includes both standard Ethereum JSON-RPC methods and Tevm-specific functionality.
Generated API Documentation: View the full API documentation in the evmts/tevm-monorepo/packages/actions/docs folder.
Installation
npm install @tevm/actions
Overview
The @tevm/actions
package provides handlers for:
- Executing EVM calls and contract interactions
- Managing blockchain state and accounts
- Standard Ethereum JSON-RPC methods
- Testing and development utilities (Anvil-compatible)
- Debugging and tracing functionality
API Reference
Error Classes
- BlobGasLimitExceededError - Error thrown when blob gas limit is exceeded
- MissingAccountError - Error thrown when an account doesn't exist
- NoForkUrlSetError - Error thrown when fork URL is required but not set
Core Types
- Address - Ethereum address type
- Abi - Contract ABI type
- Block - Ethereum block type
- BlockTag - Block reference tag (latest, earliest, etc)
Base Actions
Call Actions
- CallHandler - Handler for executing EVM calls
- CallParams - Parameters for call operations
- CallResult - Result of call execution
- BaseCallParams - Common parameters for all call operations
Contract Actions
- ContractHandler - Handler for contract interactions
- ContractParams - Parameters for contract calls
- ContractResult - Result of contract execution
Deploy Actions
- DeployHandler - Handler for contract deployment
- DeployParams - Parameters for deployment
- DeployResult - Result of deployment
Validation Functions
- validateBaseCallParams - Validate base call parameters
- validateCallParams - Validate call parameters
- validateContractParams - Validate contract parameters
- validateGetAccountParams - Validate get account parameters
- validateLoadStateParams - Validate load state parameters
- validateMineParams - Validate mine parameters
- validateSetAccountParams - Validate set account parameters
JSON-RPC Procedures
- anvilImpersonateAccountJsonRpcProcedure - Impersonate account procedure
- callProcedure - Call procedure
- getAccountProcedure - Get account procedure
- mineProcedure - Mine procedure
- requestProcedure - Request procedure
- requestBulkProcedure - Bulk request procedure
Internal Utilities
- forkAndCacheBlock - Fork and cache block utility
- handlePendingTransactionsWarning - Handle pending transactions warning
- shouldCreateTransaction - Check if transaction should be created
Ethereum JSON-RPC Actions
Account & Network
- EthAccountsHandler - List available accounts
- EthChainIdHandler - Get current chain ID
- EthCoinbaseHandler - Get coinbase address
- EthGasPriceHandler - Get current gas price
- EthBlockNumberHandler - Get current block number
State Reading
- EthGetBalanceHandler - Get account balance
- EthGetCodeHandler - Get contract code
- EthGetStorageAtHandler - Get storage at position
- EthCallHandler - Execute call without state changes
Block Operations
- EthGetBlockByHashHandler - Get block by hash
- EthGetBlockByNumberHandler - Get block by number
Anvil (Testing & Development) Actions
State Manipulation
- AnvilSetBalanceHandler - Set account balance
- AnvilSetCodeHandler - Set contract code
- AnvilSetNonceHandler - Set account nonce
- AnvilSetStorageAtHandler - Set storage at position
Mining & Chain Control
- AnvilMineHandler - Mine blocks
- AnvilSetChainIdHandler - Set chain ID
- AnvilResetHandler - Reset to initial state
Debug Actions
- DebugTraceCallHandler - Trace a call execution
- DebugTraceTransactionHandler - Trace a transaction execution
Usage Examples
Basic Call Example
import { createTevmNode } from 'tevm/node'
import { callHandler } from '@tevm/actions'
const client = createTevmNode()
const call = callHandler(client)
const result = await call({
to: '0x123...',
data: '0x456...',
value: 1000n
})
Contract Interaction Example
import { contractHandler } from '@tevm/actions'
const contract = contractHandler(client)
const result = await contract({
to: '0x123...',
abi: [...],
function: 'transfer',
args: ['0x456...', 1000n]
})
Deployment Example
import { deployHandler } from '@tevm/actions'
const deploy = deployHandler(client)
const result = await deploy({
bytecode: '0x...',
abi: [...],
args: ['constructor arg']
})
JSON-RPC Example
import { ethCallHandler } from '@tevm/actions'
const ethCall = ethCallHandler(client)
const result = await ethCall({
to: '0x123...',
data: '0x456...'
})
Error Handling
All actions support a throwOnFail
parameter to control error handling:
const result = await call({
to: '0x123...',
throwOnFail: false // Return errors in result instead of throwing
})