Skip to content
LogoLogo

Types

import type {
	CreateOptimisticHandlerOptions,
	CreateOptimisticHandlerResult,
	SessionClient,
	TxStatus,
	TxStatusSubscriber,
} from '@tevm/mud'

TxStatus

The event emitted for every intercepted write.

type TxStatus = {
	id: string
	timestamp: number
} & (
	| { status: 'simulating' | 'optimistic' }
	| { status: 'optimistic' | 'confirmed' | 'reverted'; hash: Hex }
)
FieldTypeDescription
idstringThe 4-byte hex identifier appended to the transaction calldata. Stable across the whole lifecycle of one write.
timestampnumberDate.now() when the event was emitted.
statusunionSee the table below.
hashHexPresent once the real transaction has been broadcast. Narrow with 'hash' in status.
statusEmitted when
simulatingThe local Tevm run has started.
optimisticThe local run succeeded (no hash yet), then again once the real transaction is broadcast (with hash).
confirmedThe receipt returned status: 'success'.
revertedThe receipt returned reverted; the optimistic transaction is dropped.

TxStatusSubscriber

type TxStatusSubscriber = (status: TxStatus) => void

Exceptions thrown by a subscriber are caught and logged by the handler; other subscribers still run.

SessionClient

The client shape @tevm/mud can intercept writes on — EntryKit's session client.

type SessionClient = BundlerClient<Transport, Chain, SmartAccount, Client> & {
	readonly userAddress: Address
	writeContract: (args: WriteContractParameters) => Promise<WriteContractReturnType>
}

userAddress is the user's main account (the one your MUD tables are keyed by), which is distinct from the session signer that actually signs. @tevm/mud uses userAddress as the caller of the local simulation, so _msgSender() in your systems matches what will happen on chain.

CreateOptimisticHandlerOptions

See createOptimisticHandler parameters.

CreateOptimisticHandlerResult

See createOptimisticHandler returns.

React types

From @tevm/mud/react:

import type { UseOptimisticRecordResult, UseOptimisticRecordsResult } from '@tevm/mud/react'
 
type UseOptimisticRecordResult<TTable, TDefaultValue> = TDefaultValue extends undefined
	? TableRecord<TTable> | undefined
	: TableRecord<TTable>
 
type UseOptimisticRecordsResult<TTable> = readonly TableRecord<TTable>[]