Skip to content

tevmDumpState

tevmDumpState(client): Promise<DumpStateResult<TevmDumpStateError>>

A tree-shakeable version of the tevmDumpState action for viem. Dumps the state of TEVM into a plain JavaScript object that can later be used to restore state using the tevmLoadState action.

This action is useful for persisting and restoring the state between different sessions or processes.

Parameters

client: Client<TevmTransport<string>, undefined | Chain, undefined | Account, undefined, undefined | object>

The viem client configured with TEVM transport.

Returns

Promise<DumpStateResult<TevmDumpStateError>>

The dump of the TEVM state.

Example

import { tevmDumpState } from 'tevm/actions'
import { createClient, http } from 'viem'
import { optimism } from 'tevm/common'
import { createTevmTransport } from 'tevm'
import fs from 'fs'
const client = createClient({
transport: createTevmTransport({
fork: { transport: http('https://mainnet.optimism.io')({}) }
}),
chain: optimism,
})
async function example() {
const state = await tevmDumpState(client)
fs.writeFileSync('state.json', JSON.stringify(state))
console.log('State dumped to state.json')
}
example()

See

Defined in

packages/memory-client/src/tevmDumpState.js:41