MemoryClient
MemoryClient<
TChain
,TAccountOrAddress
>:Prettify
<Client
<TevmTransport
,TChain
,TAccountOrAddress
extendsAccount
?Account
:undefined
,TevmRpcSchema
,TevmActions
&PublicActions
<TevmTransport
,TChain
,TAccountOrAddress
extendsAccount
?Account
:undefined
> &WalletActions
<TChain
,TAccountOrAddress
extendsAccount
?Account
:undefined
> &TestActions
>>
Represents a TEVM-enhanced viem client with an in-memory Ethereum client as its transport. The MemoryClient comes preloaded with all wallet, test, public, and TEVM actions, and supports both manual and auto mining modes.
This client allows for extensive interaction with the EVM, including making JSON-RPC requests, managing accounts, forking networks, and handling state persistence.
Example
See
- For creating a MemoryClient instance, see createMemoryClient.
- Client Guide
- Actions Guide
- Reference Docs
Actions API
MemoryClient supports the following viem actions:
- Test actions are included by default.
Forking
To fork an existing network, pass an EIP-1193 transport to the fork.transport
option with an optional block tag.
When you fork, TEVM will pin the block tag and lazily cache state from the fork transport.
It’s highly recommended to pass in a common
object that matches the chain. This will increase the performance of forking with known values.
The common
object extends the viem chain interface with EVM-specific information. When using TEVM, you should also use tevm/common
rather than viem/chains
or use createCommon
and pass in a viem chain.
Viem clients, including MemoryClient, are themselves EIP-1193 transports. This means you can fork a client with another client.
Mining Modes
TEVM supports two mining modes:
- Manual: Using
tevm.mine()
- Auto: Automatically mines a block after every transaction.
TEVM state does not update until blocks are mined.
Using TEVM over HTTP
TEVM can be run as an HTTP server using @tevm/server
to handle JSON-RPC requests.
This allows you to use any Ethereum client to communicate with it, including a viem public client.
State Persistence (Experimental)
It is possible to persist the TEVM client to a synchronous source using the persister
option.
Network Support
TEVM guarantees support for the following networks:
- Ethereum mainnet
- Standard OP Stack chains
Other EVM chains are likely to work but do not officially carry support. More official chain support will be added in the near future.
Note: Optimism deposit transactions are not currently supported but will be in a future release. TEVM filters out these transactions from blocks.
Network and Hardfork Support
TEVM supports enabling and disabling different EIPs, but the following EIPs are always turned on:
- 1559
- 4895
- 4844
- 4788
Currently, only EIP-1559 Fee Market transactions are supported.
Tree Shakeable Actions
TEVM supports tree-shakeable actions using createTevmNode()
and the tevm/actions
package. If you are building a UI, you should use tree-shakeable actions to optimize bundle size. These are described in detail in the actions API guide.
Composing with TEVM Contracts and Bundler
MemoryClient can compose with TEVM contracts and the TEVM bundler. For more information, see the TEVM contracts guide and the TEVM Solidity imports guide.
Type Parameters
• TChain extends Chain
| undefined
= Chain
| undefined
• TAccountOrAddress extends Account
| Address
| undefined
= Account
| Address
| undefined