createMemoryClient
createMemoryClient(
options
?):object
A local EVM instance running in JavaScript. Similar to Anvil in your browser It wraps the viem public client and test client
Parameters
• options?: BaseClientOptions
Returns
object
_tevm
_tevm:
object
&EIP1193Events
&object
&Eip1193RequestProvider
&TevmActionsApi
&object
Type declaration
extend()
readonly
extend: <TExtension
>(decorator
) =>BaseClient
<"fork"
|"normal"
,object
&TExtension
>
Extends the base client with additional functionality. This enables optimal code splitting and extensibility
Type parameters
• TExtension extends Record
<string
, any
>
Parameters
• decorator
Returns
BaseClient
<"fork"
| "normal"
, object
& TExtension
>
forkTransport?
optional
readonly
forkTransport:object
Client to make json rpc requests to a forked node
Example
forkTransport.request
request:
EIP1193RequestFn
getFilters()
readonly
getFilters: () =>Map
<`0x${string}`,Filter
>
Gets all registered filters mapped by id
Returns
Map
<`0x${string}`, Filter
>
getImpersonatedAccount()
readonly
getImpersonatedAccount: () =>undefined
| `0x${string}`
The currently impersonated account. This is only used in fork
mode
Returns
undefined
| `0x${string}`
getReceiptsManager()
readonly
getReceiptsManager: () =>Promise
<ReceiptsManager
>
Interface for querying receipts and historical state
Returns
Promise
<ReceiptsManager
>
getTxPool()
readonly
getTxPool: () =>Promise
<TxPool
>
Gets the pool of pending transactions to be included in next block
Returns
Promise
<TxPool
>
getVm()
readonly
getVm: () =>Promise
<Vm
>
Internal instance of the VM. Can be used for lower level operations. Normally not recomended to use unless building libraries or extensions on top of Tevm.
Returns
Promise
<Vm
>
logger
readonly
logger:Logger
The logger instance
miningConfig
readonly
miningConfig:MiningConfig
The configuration for mining. Defaults to ‘auto'
- 'auto’ will mine a block on every transaction
- ’interval’ will mine a block every
interval
milliseconds - ’manual’ will not mine a block automatically and requires a manual call to
mineBlock
mode
readonly
mode:"fork"
|"normal"
The mode the current client is running in
fork
mode will fetch and cache all state from the block forked from the provided URL
normal
mode will not fetch any state and will only run the EVM in memory
Example
ready()
readonly
ready: () =>Promise
<true
>
Returns promise that resulves when the client is ready The client is usable without calling this method but may have extra latency on the first call from initialization
Example
Returns
Promise
<true
>
removeFilter()
readonly
removeFilter: (id
) =>void
Removes a filter by id
Parameters
• id: `0x${string}`
Returns
void
setFilter()
readonly
setFilter: (filter
) =>void
Creates a new filter to watch for logs events and blocks
Parameters
• filter: Filter
Returns
void
setImpersonatedAccount()
readonly
setImpersonatedAccount: (address
) =>void
Sets the account to impersonate. This will allow the client to act as if it is that account On Ethereum JSON_RPC endpoints. Pass in undefined to stop impersonating
Parameters
• address: undefined
| `0x${string}`
Returns
void
Type declaration
emit()
Emit an event.
Parameters
• eventName: keyof EIP1193EventMap
The event name.
• …args: any
[]
Arguments to pass to the event listeners.
Returns
boolean
True if the event was emitted, false otherwise.
Type declaration
request
request:
EIP1193RequestFn
send
send:
TevmJsonRpcRequestHandler
sendBulk
sendBulk:
TevmJsonRpcBulkRequestHandler
account
account:
undefined
The Account of the Client.
batch?
optional
batch:object
Flags for batch settings.
batch.multicall?
optional
multicall:boolean
|object
Toggle to enable eth_call
multicall aggregation.
cacheTime
cacheTime:
number
Time (in ms) that cached data will remain in memory.
call()
call: (
parameters
) =>Promise
<CallReturnType
>
Executes a new message call immediately without submitting a transaction to the network.
- Docs: https://viem.sh/docs/actions/public/call
- JSON-RPC Methods:
eth_call
Example
Parameters
• parameters: CallParameters
<undefined
| Chain
>
Returns
Promise
<CallReturnType
>
ccipRead?
optional
ccipRead:false
|object
CCIP Read configuration.
chain
chain:
undefined
Chain for the client.
createBlockFilter()
createBlockFilter: () =>
Promise
<object
>
Creates a Filter to listen for new block hashes that can be used with getFilterChanges
.
- Docs: https://viem.sh/docs/actions/public/createBlockFilter
- JSON-RPC Methods:
eth_newBlockFilter
Example
Returns
Promise
<object
>
id
id: `0x${string}`
request
request:
EIP1193RequestFn
<readonly [object
,object
,object
]>
type
type:
"block"
createContractEventFilter()
createContractEventFilter: <
TAbi
,TEventName
,TArgs
,TStrict
,TFromBlock
,TToBlock
>(args
) =>Promise
<CreateContractEventFilterReturnType
<TAbi
,TEventName
,TArgs
,TStrict
,TFromBlock
,TToBlock
>>
Creates a Filter to retrieve event logs that can be used with getFilterChanges
or getFilterLogs
.
Example
Type parameters
• TAbi extends Abi
| readonly unknown
[]
• TEventName extends undefined
| string
• TArgs extends undefined
| Record
<string
, unknown
> | readonly unknown
[]
• TStrict extends undefined
| boolean
= undefined
• TFromBlock extends undefined
| bigint
| BlockTag
= undefined
• TToBlock extends undefined
| bigint
| BlockTag
= undefined
Parameters
• args: CreateContractEventFilterParameters
<TAbi
, TEventName
, TArgs
, TStrict
, TFromBlock
, TToBlock
>
CreateContractEventFilterParameters
Returns
Promise
<CreateContractEventFilterReturnType
<TAbi
, TEventName
, TArgs
, TStrict
, TFromBlock
, TToBlock
>>
createEventFilter()
createEventFilter: <
TAbiEvent
,TAbiEvents
,TStrict
,TFromBlock
,TToBlock
,_EventName
,_Args
>(args
?) =>Promise
<{ [K in string | number | symbol]: Filter<“event”, TAbiEvents, _EventName, _Args, TStrict, TFromBlock, TToBlock>[K] }>
Creates a Filter
to listen for new events that can be used with getFilterChanges
.
- Docs: https://viem.sh/docs/actions/public/createEventFilter
- JSON-RPC Methods:
eth_newFilter
Example
Type parameters
• TAbiEvent extends undefined
| AbiEvent
= undefined
• TAbiEvents extends undefined
| readonly unknown
[] | readonly AbiEvent
[] = TAbiEvent
extends AbiEvent
? [TAbiEvent
<TAbiEvent
>] : undefined
• TStrict extends undefined
| boolean
= undefined
• TFromBlock extends undefined
| bigint
| BlockTag
= undefined
• TToBlock extends undefined
| bigint
| BlockTag
= undefined
• _EventName extends undefined
| string
= MaybeAbiEventName
<TAbiEvent
>
• _Args extends undefined
| Record
<string
, unknown
> | readonly unknown
[] = undefined
Parameters
• args?: CreateEventFilterParameters
<TAbiEvent
, TAbiEvents
, TStrict
, TFromBlock
, TToBlock
, _EventName
, _Args
>
Returns
Promise
<{ [K in string | number | symbol]: Filter<“event”, TAbiEvents, _EventName, _Args, TStrict, TFromBlock, TToBlock>[K] }>
createPendingTransactionFilter()
createPendingTransactionFilter: () =>
Promise
<object
>
Creates a Filter to listen for new pending transaction hashes that can be used with getFilterChanges
.
- Docs: https://viem.sh/docs/actions/public/createPendingTransactionFilter
- JSON-RPC Methods:
eth_newPendingTransactionFilter
Example
Returns
Promise
<object
>
id
id: `0x${string}`
request
request:
EIP1193RequestFn
<readonly [object
,object
,object
]>
type
type:
"transaction"
estimateContractGas()
estimateContractGas: <
TChain
,abi
,functionName
,args
>(args
) =>Promise
<bigint
>
Estimates the gas required to successfully execute a contract write function call.
Remarks
Internally, uses a Public Client to call the estimateGas
action with ABI-encoded data
.
Example
Type parameters
• TChain extends undefined
| Chain
• abi extends Abi
| readonly unknown
[]
• functionName extends string
• args extends unknown
Parameters
• args: EstimateContractGasParameters
<abi
, functionName
, args
, TChain
>
EstimateContractGasParameters
Returns
Promise
<bigint
>
estimateFeesPerGas()
estimateFeesPerGas: <
TChainOverride
,TType
>(args
?) =>Promise
<EstimateFeesPerGasReturnType
>
Returns an estimate for the fees per gas for a transaction to be included in the next block.
Example
Type parameters
• TChainOverride extends undefined
| Chain
= undefined
• TType extends FeeValuesType
= "eip1559"
Parameters
• args?: EstimateFeesPerGasParameters
<undefined
| Chain
, TChainOverride
, TType
>
Returns
Promise
<EstimateFeesPerGasReturnType
>
estimateGas()
estimateGas: (
args
) =>Promise
<bigint
>
Estimates the gas necessary to complete a transaction without submitting it to the network.
- Docs: https://viem.sh/docs/actions/public/estimateGas
- JSON-RPC Methods:
eth_estimateGas
Example
Parameters
• args: EstimateGasParameters
<undefined
| Chain
>
EstimateGasParameters
Returns
Promise
<bigint
>
estimateMaxPriorityFeePerGas()
estimateMaxPriorityFeePerGas: <
TChainOverride
>(args
?) =>Promise
<bigint
>
Returns an estimate for the max priority fee per gas (in wei) for a transaction to be included in the next block.
Example
Type parameters
• TChainOverride extends undefined
| Chain
= undefined
Parameters
• args?
• args.chain?: null
| TChainOverride
Returns
Promise
<bigint
>
extend()
extend: <
client
>(fn
) =>Client
<Transport
,undefined
,undefined
, [object
,object
,object
,object
,object
], { [K in string | number | symbol]: client[K] } &PublicActions
&TevmActions
>
Type parameters
• client extends object
& ExactPartial
<ExtendableProtectedActions
<Transport
, undefined
, undefined
>>
Parameters
• fn
Returns
Client
<Transport
, undefined
, undefined
, [object
, object
, object
, object
, object
], { [K in string | number | symbol]: client[K] } & PublicActions
& TevmActions
>
getBalance()
getBalance: (
args
) =>Promise
<bigint
>
Returns the balance of an address in wei.
- Docs: https://viem.sh/docs/actions/public/getBalance
- JSON-RPC Methods:
eth_getBalance
Remarks
You can convert the balance to ether units with formatEther
.
Example
Parameters
• args: GetBalanceParameters
GetBalanceParameters
Returns
Promise
<bigint
>
getBlobBaseFee()
getBlobBaseFee: () =>
Promise
<bigint
>
Returns the base fee per blob gas in wei.
- Docs: https://viem.sh/docs/actions/public/getBlobBaseFee
- JSON-RPC Methods:
eth_blobBaseFee
Example
Returns
Promise
<bigint
>
getBlock()
getBlock: <
TIncludeTransactions
,TBlockTag
>(args
?) =>Promise
<object
>
Returns information about a block at a block number, hash, or tag.
- Docs: https://viem.sh/docs/actions/public/getBlock
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks/fetching-blocks
- JSON-RPC Methods:
- Calls
eth_getBlockByNumber
forblockNumber
&blockTag
. - Calls
eth_getBlockByHash
forblockHash
.
- Calls
Example
Type parameters
• TIncludeTransactions extends boolean
= false
• TBlockTag extends BlockTag
= "latest"
Parameters
• args?: GetBlockParameters
<TIncludeTransactions
, TBlockTag
>
GetBlockParameters
Returns
Promise
<object
>
baseFeePerGas
baseFeePerGas:
null
|bigint
Base fee per gas
blobGasUsed
blobGasUsed:
bigint
Total used blob gas by all transactions in this block
difficulty
difficulty:
bigint
Difficulty for this block
excessBlobGas
excessBlobGas:
bigint
Excess blob gas
extraData
extraData: `0x${string}`
“Extra data” field of this block
gasLimit
gasLimit:
bigint
Maximum gas allowed in this block
gasUsed
gasUsed:
bigint
Total used gas by all transactions in this block
hash
hash:
TBlockTag
extends"pending"
?null
: `0x${string}`
Block hash or null
if pending
logsBloom
logsBloom:
TBlockTag
extends"pending"
?null
: `0x${string}`
Logs bloom filter or null
if pending
miner
miner: `0x${string}`
Address that received this block’s mining rewards
mixHash
mixHash: `0x${string}`
Unique identifier for the block.
nonce
nonce:
TBlockTag
extends"pending"
?null
: `0x${string}`
Proof-of-work hash or null
if pending
number
number:
TBlockTag
extends"pending"
?null
:bigint
Block number or null
if pending
parentHash
parentHash: `0x${string}`
Parent block hash
receiptsRoot
receiptsRoot: `0x${string}`
Root of the this block’s receipts trie
sealFields
sealFields: `0x${string}`[]
sha3Uncles
sha3Uncles: `0x${string}`
SHA3 of the uncles data in this block
size
size:
bigint
Size of this block in bytes
stateRoot
stateRoot: `0x${string}`
Root of this block’s final state trie
timestamp
timestamp:
bigint
Unix timestamp of when this block was collated
totalDifficulty
totalDifficulty:
null
|bigint
Total difficulty of the chain until this block
transactions
transactions:
TIncludeTransactions
extendstrue
? (object
|object
|object
|object
)[] : `0x${string}`[]
transactionsRoot
transactionsRoot: `0x${string}`
Root of this block’s transaction trie
uncles
uncles: `0x${string}`[]
List of uncle hashes
withdrawals?
optional
withdrawals:Withdrawal
[]
List of withdrawal objects
withdrawalsRoot?
optional
withdrawalsRoot: `0x${string}`
Root of the this block’s withdrawals trie
getBlockNumber()
getBlockNumber: (
args
?) =>Promise
<bigint
>
Returns the number of the most recent block seen.
- Docs: https://viem.sh/docs/actions/public/getBlockNumber
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks/fetching-blocks
- JSON-RPC Methods:
eth_blockNumber
Example
Parameters
• args?: GetBlockNumberParameters
GetBlockNumberParameters
Returns
Promise
<bigint
>
getBlockTransactionCount()
getBlockTransactionCount: (
args
?) =>Promise
<number
>
Returns the number of Transactions at a block number, hash, or tag.
- Docs: https://viem.sh/docs/actions/public/getBlockTransactionCount
- JSON-RPC Methods:
- Calls
eth_getBlockTransactionCountByNumber
forblockNumber
&blockTag
. - Calls
eth_getBlockTransactionCountByHash
forblockHash
.
- Calls
Example
Parameters
• args?: GetBlockTransactionCountParameters
GetBlockTransactionCountParameters
Returns
Promise
<number
>
getBytecode()
getBytecode: (
args
) =>Promise
<GetBytecodeReturnType
>
Retrieves the bytecode at an address.
- Docs: https://viem.sh/docs/contract/getBytecode
- JSON-RPC Methods:
eth_getCode
Example
Parameters
• args: GetBytecodeParameters
GetBytecodeParameters
Returns
Promise
<GetBytecodeReturnType
>
getChainId()
getChainId: () =>
Promise
<number
>
Returns the chain ID associated with the current network.
- Docs: https://viem.sh/docs/actions/public/getChainId
- JSON-RPC Methods:
eth_chainId
Example
Returns
Promise
<number
>
getContractEvents()
getContractEvents: <
abi
,eventName
,strict
,fromBlock
,toBlock
>(args
) =>Promise
<GetContractEventsReturnType
<abi
,eventName
,strict
,fromBlock
,toBlock
>>
Returns a list of event logs emitted by a contract.
- Docs: https://viem.sh/docs/actions/public/getContractEvents
- JSON-RPC Methods:
eth_getLogs
Example
Type parameters
• abi extends Abi
| readonly unknown
[]
• eventName extends undefined
| string
= undefined
• strict extends undefined
| boolean
= undefined
• fromBlock extends undefined
| bigint
| BlockTag
= undefined
• toBlock extends undefined
| bigint
| BlockTag
= undefined
Parameters
• args: GetContractEventsParameters
<abi
, eventName
, strict
, fromBlock
, toBlock
>
Returns
Promise
<GetContractEventsReturnType
<abi
, eventName
, strict
, fromBlock
, toBlock
>>
getEnsAddress()
getEnsAddress: (
args
) =>Promise
<GetEnsAddressReturnType
>
Gets address for ENS name.
- Docs: https://viem.sh/docs/ens/actions/getEnsAddress
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
Remarks
Calls resolve(bytes, bytes)
on ENS Universal Resolver Contract.
Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to getEnsAddress
. You can use the built-in normalize
function for this.
Example
Parameters
• args
GetEnsAddressParameters
• args.blockNumber?: bigint
The balance of the account at a block number.
• args.blockTag?: BlockTag
The balance of the account at a block tag.
Default
• args.coinType?: number
ENSIP-9 compliant coinType used to resolve addresses for other chains
• args.gatewayUrls?: string
[]
Universal Resolver gateway URLs to use for resolving CCIP-read requests.
• args.name: string
Name to get the address for.
• args.strict?: boolean
Whether or not to throw errors propagated from the ENS Universal Resolver Contract.
• args.universalResolverAddress?: `0x${string}`
Address of ENS Universal Resolver Contract.
Returns
Promise
<GetEnsAddressReturnType
>
getEnsAvatar()
getEnsAvatar: (
args
) =>Promise
<GetEnsAvatarReturnType
>
Gets the avatar of an ENS name.
- Docs: https://viem.sh/docs/ens/actions/getEnsAvatar
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
Remarks
Calls getEnsText
with key
set to 'avatar'
.
Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to getEnsAddress
. You can use the built-in normalize
function for this.
Example
Parameters
• args
GetEnsAvatarParameters
• args.assetGatewayUrls?: AssetGatewayUrls
Gateway urls to resolve IPFS and/or Arweave assets.
• args.blockNumber?: bigint
The balance of the account at a block number.
• args.blockTag?: BlockTag
The balance of the account at a block tag.
Default
• args.gatewayUrls?: string
[]
Universal Resolver gateway URLs to use for resolving CCIP-read requests.
• args.name: string
ENS name to get Text for.
• args.strict?: boolean
Whether or not to throw errors propagated from the ENS Universal Resolver Contract.
• args.universalResolverAddress?: `0x${string}`
Address of ENS Universal Resolver Contract.
Returns
Promise
<GetEnsAvatarReturnType
>
getEnsName()
getEnsName: (
args
) =>Promise
<GetEnsNameReturnType
>
Gets primary name for specified address.
- Docs: https://viem.sh/docs/ens/actions/getEnsName
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
Remarks
Calls reverse(bytes)
on ENS Universal Resolver Contract to “reverse resolve” the address to the primary ENS name.
Example
Parameters
• args
GetEnsNameParameters
• args.address: `0x${string}`
Address to get ENS name for.
• args.blockNumber?: bigint
The balance of the account at a block number.
• args.blockTag?: BlockTag
The balance of the account at a block tag.
Default
• args.gatewayUrls?: string
[]
Universal Resolver gateway URLs to use for resolving CCIP-read requests.
• args.strict?: boolean
Whether or not to throw errors propagated from the ENS Universal Resolver Contract.
• args.universalResolverAddress?: `0x${string}`
Address of ENS Universal Resolver Contract.
Returns
Promise
<GetEnsNameReturnType
>
getEnsResolver()
getEnsResolver: (
args
) =>Promise
<`0x${string}`>
Gets resolver for ENS name.
- Docs: https://viem.sh/docs/ens/actions/getEnsResolver
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
Remarks
Calls findResolver(bytes)
on ENS Universal Resolver Contract to retrieve the resolver of an ENS name.
Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to getEnsAddress
. You can use the built-in normalize
function for this.
Example
Parameters
• args
GetEnsResolverParameters
• args.blockNumber?: bigint
The balance of the account at a block number.
• args.blockTag?: BlockTag
The balance of the account at a block tag.
Default
• args.name: string
Name to get the address for.
• args.universalResolverAddress?: `0x${string}`
Address of ENS Universal Resolver Contract.
Returns
Promise
<`0x${string}`>
getEnsText()
getEnsText: (
args
) =>Promise
<GetEnsTextReturnType
>
Gets a text record for specified ENS name.
- Docs: https://viem.sh/docs/ens/actions/getEnsResolver
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
Remarks
Calls resolve(bytes, bytes)
on ENS Universal Resolver Contract.
Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to getEnsAddress
. You can use the built-in normalize
function for this.
Example
Parameters
• args
GetEnsTextParameters
• args.blockNumber?: bigint
The balance of the account at a block number.
• args.blockTag?: BlockTag
The balance of the account at a block tag.
Default
• args.gatewayUrls?: string
[]
Universal Resolver gateway URLs to use for resolving CCIP-read requests.
• args.key: string
Text record to retrieve.
• args.name: string
ENS name to get Text for.
• args.strict?: boolean
Whether or not to throw errors propagated from the ENS Universal Resolver Contract.
• args.universalResolverAddress?: `0x${string}`
Address of ENS Universal Resolver Contract.
Returns
Promise
<GetEnsTextReturnType
>
getFeeHistory()
getFeeHistory: (
args
) =>Promise
<GetFeeHistoryReturnType
>
Returns a collection of historical gas information.
- Docs: https://viem.sh/docs/actions/public/getFeeHistory
- JSON-RPC Methods:
eth_feeHistory
Example
Parameters
• args: GetFeeHistoryParameters
GetFeeHistoryParameters
Returns
Promise
<GetFeeHistoryReturnType
>
getFilterChanges()
getFilterChanges: <
TFilterType
,TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>(args
) =>Promise
<GetFilterChangesReturnType
<TFilterType
,TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>>
Returns a list of logs or hashes based on a Filter since the last time it was called.
- Docs: https://viem.sh/docs/actions/public/getFilterChanges
- JSON-RPC Methods:
eth_getFilterChanges
Remarks
A Filter can be created from the following actions:
Depending on the type of filter, the return value will be different:
- If the filter was created with
createContractEventFilter
orcreateEventFilter
, it returns a list of logs. - If the filter was created with
createPendingTransactionFilter
, it returns a list of transaction hashes. - If the filter was created with
createBlockFilter
, it returns a list of block hashes.
Examples
Type parameters
• TFilterType extends FilterType
• TAbi extends undefined
| Abi
| readonly unknown
[]
• TEventName extends undefined
| string
• TStrict extends undefined
| boolean
= undefined
• TFromBlock extends undefined
| bigint
| BlockTag
= undefined
• TToBlock extends undefined
| bigint
| BlockTag
= undefined
Parameters
• args: GetFilterChangesParameters
<TFilterType
, TAbi
, TEventName
, TStrict
, TFromBlock
, TToBlock
>
GetFilterChangesParameters
Returns
Promise
<GetFilterChangesReturnType
<TFilterType
, TAbi
, TEventName
, TStrict
, TFromBlock
, TToBlock
>>
getFilterLogs()
getFilterLogs: <
TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>(args
) =>Promise
<GetFilterLogsReturnType
<TAbi
,TEventName
,TStrict
,TFromBlock
,TToBlock
>>
Returns a list of event logs since the filter was created.
- Docs: https://viem.sh/docs/actions/public/getFilterLogs
- JSON-RPC Methods:
eth_getFilterLogs
Remarks
getFilterLogs
is only compatible with event filters.
Example
Type parameters
• TAbi extends undefined
| Abi
| readonly unknown
[]
• TEventName extends undefined
| string
• TStrict extends undefined
| boolean
= undefined
• TFromBlock extends undefined
| bigint
| BlockTag
= undefined
• TToBlock extends undefined
| bigint
| BlockTag
= undefined
Parameters
• args: GetFilterLogsParameters
<TAbi
, TEventName
, TStrict
, TFromBlock
, TToBlock
>
GetFilterLogsParameters
Returns
Promise
<GetFilterLogsReturnType
<TAbi
, TEventName
, TStrict
, TFromBlock
, TToBlock
>>
getGasPrice()
getGasPrice: () =>
Promise
<bigint
>
Returns the current price of gas (in wei).
- Docs: https://viem.sh/docs/actions/public/getGasPrice
- JSON-RPC Methods:
eth_gasPrice
Example
Returns
Promise
<bigint
>
getLogs()
getLogs: <
TAbiEvent
,TAbiEvents
,TStrict
,TFromBlock
,TToBlock
>(args
?) =>Promise
<GetLogsReturnType
<TAbiEvent
,TAbiEvents
,TStrict
,TFromBlock
,TToBlock
>>
Returns a list of event logs matching the provided parameters.
- Docs: https://viem.sh/docs/actions/public/getLogs
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/filters-and-logs/event-logs
- JSON-RPC Methods:
eth_getLogs
Example
Type parameters
• TAbiEvent extends undefined
| AbiEvent
= undefined
• TAbiEvents extends undefined
| readonly unknown
[] | readonly AbiEvent
[] = TAbiEvent
extends AbiEvent
? [TAbiEvent
<TAbiEvent
>] : undefined
• TStrict extends undefined
| boolean
= undefined
• TFromBlock extends undefined
| bigint
| BlockTag
= undefined
• TToBlock extends undefined
| bigint
| BlockTag
= undefined
Parameters
• args?: GetLogsParameters
<TAbiEvent
, TAbiEvents
, TStrict
, TFromBlock
, TToBlock
>
GetLogsParameters
Returns
Promise
<GetLogsReturnType
<TAbiEvent
, TAbiEvents
, TStrict
, TFromBlock
, TToBlock
>>
getProof()
getProof: (
args
) =>Promise
<GetProofReturnType
>
Returns the account and storage values of the specified account including the Merkle-proof.
- Docs: https://viem.sh/docs/actions/public/getProof
- JSON-RPC Methods:
- Calls
eth_getProof
- Calls
Example
Parameters
• args: GetProofParameters
Returns
Promise
<GetProofReturnType
>
getStorageAt()
getStorageAt: (
args
) =>Promise
<GetStorageAtReturnType
>
Returns the value from a storage slot at a given address.
- Docs: https://viem.sh/docs/contract/getStorageAt
- JSON-RPC Methods:
eth_getStorageAt
Example
Parameters
• args: GetStorageAtParameters
GetStorageAtParameters
Returns
Promise
<GetStorageAtReturnType
>
getTransaction()
getTransaction: <
TBlockTag
>(args
) =>Promise
<object
|object
|object
|object
>
Returns information about a Transaction given a hash or block identifier.
- Docs: https://viem.sh/docs/actions/public/getTransaction
- Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions/fetching-transactions
- JSON-RPC Methods:
eth_getTransactionByHash
Example
Type parameters
• TBlockTag extends BlockTag
= "latest"
Parameters
• args: GetTransactionParameters
<TBlockTag
>
GetTransactionParameters
Returns
Promise
<object
| object
| object
| object
>
getTransactionConfirmations()
getTransactionConfirmations: (
args
) =>Promise
<bigint
>
Returns the number of blocks passed (confirmations) since the transaction was processed on a block.
- Docs: https://viem.sh/docs/actions/public/getTransactionConfirmations
- Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions/fetching-transactions
- JSON-RPC Methods:
eth_getTransactionConfirmations
Example
Parameters
• args: GetTransactionConfirmationsParameters
<undefined
| Chain
>
GetTransactionConfirmationsParameters
Returns
Promise
<bigint
>
getTransactionCount()
getTransactionCount: (
args
) =>Promise
<number
>
Returns the number of Transactions an Account has broadcast / sent.
- Docs: https://viem.sh/docs/actions/public/getTransactionCount
- JSON-RPC Methods:
eth_getTransactionCount
Example
Parameters
• args: GetTransactionCountParameters
GetTransactionCountParameters
Returns
Promise
<number
>
getTransactionReceipt()
getTransactionReceipt: (
args
) =>Promise
<TransactionReceipt
>
Returns the Transaction Receipt given a Transaction hash.
- Docs: https://viem.sh/docs/actions/public/getTransactionReceipt
- Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions/fetching-transactions
- JSON-RPC Methods:
eth_getTransactionReceipt
Example
Parameters
• args: GetTransactionReceiptParameters
GetTransactionReceiptParameters
Returns
Promise
<TransactionReceipt
>
key
key:
string
A key for the client.
multicall()
multicall: <
contracts
,allowFailure
>(args
) =>Promise
<MulticallReturnType
<contracts
,allowFailure
>>
Similar to readContract
, but batches up multiple functions on a contract in a single RPC call via the multicall3
contract.
Example
Type parameters
• contracts extends readonly unknown
[]
• allowFailure extends boolean
= true
Parameters
• args: MulticallParameters
<contracts
, allowFailure
>
MulticallParameters
Returns
Promise
<MulticallReturnType
<contracts
, allowFailure
>>
name
name:
string
A name for the client.
pollingInterval
pollingInterval:
number
Frequency (in ms) for polling enabled actions & events. Defaults to 4_000 milliseconds.
prepareTransactionRequest()
prepareTransactionRequest: <
TRequest
,TChainOverride
,TAccountOverride
>(args
) =>Promise
<{ [K in string | number | symbol]: (UnionRequiredBy<Extract<UnionOmit<(…), (…)> & ((…) extends (…) ? (…) : (…)) & ((…) extends (…) ? (…) : (…)), IsNever<(…)> extends true ? unknown : ExactPartial<(…)>> & Object, ParameterTypeToParameters<TRequest[“parameters”] extends readonly PrepareTransactionRequestParameterType[] ? any[any][number] : “gas” | “nonce” | “blobVersionedHashes” | “chainId” | “type” | “fees”>> & (unknown extends TRequest[“kzg”] ? Object : Pick<TRequest, “kzg”>))[K] }>
Prepares a transaction request for signing.
Examples
Type parameters
• TRequest extends Omit
<object
, "from"
> | Omit
<object
, "from"
> | Omit
<object
, "from"
> | Omit
<object
, "from"
> & object
& object
• TChainOverride extends undefined
| Chain
= undefined
• TAccountOverride extends undefined
| `0x${string}` | Account
= undefined
Parameters
• args: PrepareTransactionRequestParameters
<undefined
| Chain
, undefined
| Account
, TChainOverride
, TAccountOverride
, TRequest
>
PrepareTransactionRequestParameters
Returns
Promise
<{ [K in string | number | symbol]: (UnionRequiredBy<Extract<UnionOmit<(…), (…)> & ((…) extends (…) ? (…) : (…)) & ((…) extends (…) ? (…) : (…)), IsNever<(…)> extends true ? unknown : ExactPartial<(…)>> & Object, ParameterTypeToParameters<TRequest[“parameters”] extends readonly PrepareTransactionRequestParameterType[] ? any[any][number] : “gas” | “nonce” | “blobVersionedHashes” | “chainId” | “type” | “fees”>> & (unknown extends TRequest[“kzg”] ? Object : Pick<TRequest, “kzg”>))[K] }>
readContract()
readContract: <
abi
,functionName
,args
>(args
) =>Promise
<ReadContractReturnType
<abi
,functionName
,args
>>
Calls a read-only function on a contract, and returns the response.
- Docs: https://viem.sh/docs/contract/readContract
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/contracts/reading-contracts
Remarks
A “read-only” function (constant function) on a Solidity contract is denoted by a view
or pure
keyword. They can only read the state of the contract, and cannot make any changes to it. Since read-only methods do not change the state of the contract, they do not require any gas to be executed, and can be called by any user without the need to pay for gas.
Internally, uses a Public Client to call the call
action with ABI-encoded data
.
Example
Type parameters
• abi extends Abi
| readonly unknown
[]
• functionName extends string
• args extends unknown
Parameters
• args: ReadContractParameters
<abi
, functionName
, args
>
ReadContractParameters
Returns
Promise
<ReadContractReturnType
<abi
, functionName
, args
>>
request
request:
EIP1193RequestFn
<[object
,object
,object
,object
,object
]>
Request function wrapped with friendly error handling
sendRawTransaction()
sendRawTransaction: (
args
) =>Promise
<`0x${string}`>
Sends a signed transaction to the network
- Docs: https://viem.sh/docs/actions/wallet/sendRawTransaction
- JSON-RPC Method:
eth_sendRawTransaction
Example
Parameters
• args: SendRawTransactionParameters
Returns
Promise
<`0x${string}`>
simulateContract()
simulateContract: <
abi
,functionName
,args
,chainOverride
,accountOverride
>(args
) =>Promise
<SimulateContractReturnType
<abi
,functionName
,args
,undefined
|Chain
,undefined
|Account
,chainOverride
,accountOverride
>>
Simulates/validates a contract interaction. This is useful for retrieving return data and revert reasons of contract write functions.
- Docs: https://viem.sh/docs/contract/simulateContract
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/contracts/writing-to-contracts
Remarks
This function does not require gas to execute and does not change the state of the blockchain. It is almost identical to readContract
, but also supports contract write functions.
Internally, uses a Public Client to call the call
action with ABI-encoded data
.
Example
Type parameters
• abi extends Abi
| readonly unknown
[]
• functionName extends string
• args extends unknown
• chainOverride extends undefined
| Chain
• accountOverride extends undefined
| `0x${string}` | Account
= undefined
Parameters
• args: SimulateContractParameters
<abi
, functionName
, args
, undefined
| Chain
, chainOverride
, accountOverride
>
SimulateContractParameters
Returns
Promise
<SimulateContractReturnType
<abi
, functionName
, args
, undefined
| Chain
, undefined
| Account
, chainOverride
, accountOverride
>>
tevmCall
tevmCall:
CallHandler
tevmContract
tevmContract:
ContractHandler
tevmDeploy
tevmDeploy:
DeployHandler
tevmDumpState
tevmDumpState:
DumpStateHandler
tevmForkUrl?
optional
tevmForkUrl:string
tevmGetAccount
tevmGetAccount:
GetAccountHandler
tevmLoadState
tevmLoadState:
LoadStateHandler
tevmMine
tevmMine:
MineHandler
tevmReady()
tevmReady: () =>
Promise
<true
>
Returns
Promise
<true
>
tevmScript
tevmScript:
ScriptHandler
tevmSetAccount
tevmSetAccount:
SetAccountHandler
transport
transport:
TransportConfig
<string
,EIP1193RequestFn
> &Record
<string
,any
>
The RPC transport
type
type:
string
The type of client.
uid
uid:
string
A unique ID for the client.
uninstallFilter()
uninstallFilter: (
args
) =>Promise
<boolean
>
Destroys a Filter that was created from one of the following Actions:
-
JSON-RPC Methods:
eth_uninstallFilter
Example
Parameters
• args: UninstallFilterParameters
UninstallFilterParameters
Returns
Promise
<boolean
>
verifyMessage()
verifyMessage: (
args
) =>Promise
<boolean
>
Verify that a message was signed by the provided address.
Compatible with Smart Contract Accounts & Externally Owned Accounts via ERC-6492.
Parameters
• args
• args.address: `0x${string}`
The address that signed the original message.
• args.blockNumber?: bigint
The balance of the account at a block number.
• args.blockTag?: BlockTag
The balance of the account at a block tag.
Default
• args.message: SignableMessage
The message to be verified.
• args.signature: `0x${string}` | Uint8Array
| Signature
The signature that was generated by signing the message with the address’s private key.
Returns
Promise
<boolean
>
verifySiweMessage()
verifySiweMessage: (
args
) =>Promise
<boolean
>
Verifies EIP-4361 formatted message was signed.
Compatible with Smart Contract Accounts & Externally Owned Accounts via ERC-6492.
Parameters
• args
• args.address?: `0x${string}`
Ethereum address to check against.
• args.blockNumber?: bigint
The balance of the account at a block number.
• args.blockTag?: BlockTag
The balance of the account at a block tag.
Default
• args.domain?: string
RFC 3986 authority to check against.
• args.message: string
EIP-4361 formatted message.
• args.nonce?: string
Random string to check against.
• args.scheme?: string
RFC 3986 URI scheme to check against.
• args.signature: `0x${string}`
Signature to check against.
• args.time?: Date
Current time to check optional expirationTime
and notBefore
fields.
Default
Returns
Promise
<boolean
>
verifyTypedData()
verifyTypedData: (
args
) =>Promise
<boolean
>
Verify that typed data was signed by the provided address.
Parameters
• args: VerifyTypedDataParameters
Returns
Promise
<boolean
>
waitForTransactionReceipt()
waitForTransactionReceipt: (
args
) =>Promise
<TransactionReceipt
>
Waits for the Transaction to be included on a Block (one confirmation), and then returns the Transaction Receipt. If the Transaction reverts, then the action will throw an error.
- Docs: https://viem.sh/docs/actions/public/waitForTransactionReceipt
- Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions/sending-transactions
- JSON-RPC Methods:
- Polls
eth_getTransactionReceipt
on each block until it has been processed. - If a Transaction has been replaced:
- Calls
eth_getBlockByNumber
and extracts the transactions - Checks if one of the Transactions is a replacement
- If so, calls
eth_getTransactionReceipt
.
- Calls
- Polls
Remarks
The waitForTransactionReceipt
action additionally supports Replacement detection (e.g. sped up Transactions).
Transactions can be replaced when a user modifies their transaction in their wallet (to speed up or cancel). Transactions are replaced when they are sent from the same nonce.
There are 3 types of Transaction Replacement reasons:
repriced
: The gas price has been modified (e.g. differentmaxFeePerGas
)cancelled
: The Transaction has been cancelled (e.g.value === 0n
)replaced
: The Transaction has been replaced (e.g. differentvalue
ordata
)
Example
Parameters
• args: WaitForTransactionReceiptParameters
<undefined
| Chain
>
WaitForTransactionReceiptParameters
Returns
Promise
<TransactionReceipt
>
watchBlockNumber()
watchBlockNumber: (
args
) =>WatchBlockNumberReturnType
Watches and returns incoming block numbers.
- Docs: https://viem.sh/docs/actions/public/watchBlockNumber
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks/watching-blocks
- JSON-RPC Methods:
- When
poll: true
, callseth_blockNumber
on a polling interval. - When
poll: false
& WebSocket Transport, uses a WebSocket subscription viaeth_subscribe
and the"newHeads"
event.
- When
Example
Parameters
• args: WatchBlockNumberParameters
WatchBlockNumberParameters
Returns
WatchBlockNumberReturnType
watchBlocks()
watchBlocks: <
TIncludeTransactions
,TBlockTag
>(args
) =>WatchBlocksReturnType
Watches and returns information for incoming blocks.
- Docs: https://viem.sh/docs/actions/public/watchBlocks
- Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks/watching-blocks
- JSON-RPC Methods:
- When
poll: true
, callseth_getBlockByNumber
on a polling interval. - When
poll: false
& WebSocket Transport, uses a WebSocket subscription viaeth_subscribe
and the"newHeads"
event.
- When
Example
Type parameters
• TIncludeTransactions extends boolean
= false
• TBlockTag extends BlockTag
= "latest"
Parameters
• args: WatchBlocksParameters
<Transport
, undefined
| Chain
, TIncludeTransactions
, TBlockTag
>
WatchBlocksParameters
Returns
WatchBlocksReturnType
watchContractEvent()
watchContractEvent: <
TAbi
,TEventName
,TStrict
>(args
) =>WatchContractEventReturnType
Watches and returns emitted contract event logs.
Remarks
This Action will batch up all the event logs found within the pollingInterval
, and invoke them via onLogs
.
watchContractEvent
will attempt to create an Event Filter and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. eth_newFilter
), then watchContractEvent
will fall back to using getLogs
instead.
Example
Type parameters
• TAbi extends Abi
| readonly unknown
[]
• TEventName extends string
• TStrict extends undefined
| boolean
= undefined
Parameters
• args: WatchContractEventParameters
<TAbi
, TEventName
, TStrict
, Transport
>
WatchContractEventParameters
Returns
WatchContractEventReturnType
watchEvent()
watchEvent: <
TAbiEvent
,TAbiEvents
,TStrict
>(args
) =>WatchEventReturnType
Watches and returns emitted Event Logs.
- Docs: https://viem.sh/docs/actions/public/watchEvent
- JSON-RPC Methods:
- RPC Provider supports
eth_newFilter
:- Calls
eth_newFilter
to create a filter (called on initialize). - On a polling interval, it will call
eth_getFilterChanges
.
- Calls
- RPC Provider does not support
eth_newFilter
:- Calls
eth_getLogs
for each block between the polling interval.
- Calls
- RPC Provider supports
Remarks
This Action will batch up all the Event Logs found within the pollingInterval
, and invoke them via onLogs
.
watchEvent
will attempt to create an Event Filter and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. eth_newFilter
), then watchEvent
will fall back to using getLogs
instead.
Example
Type parameters
• TAbiEvent extends undefined
| AbiEvent
= undefined
• TAbiEvents extends undefined
| readonly unknown
[] | readonly AbiEvent
[] = TAbiEvent
extends AbiEvent
? [TAbiEvent
<TAbiEvent
>] : undefined
• TStrict extends undefined
| boolean
= undefined
Parameters
• args: WatchEventParameters
<TAbiEvent
, TAbiEvents
, TStrict
, Transport
>
WatchEventParameters
Returns
WatchEventReturnType
watchPendingTransactions()
watchPendingTransactions: (
args
) =>WatchPendingTransactionsReturnType
Watches and returns pending transaction hashes.
- Docs: https://viem.sh/docs/actions/public/watchPendingTransactions
- JSON-RPC Methods:
- When
poll: true
- Calls
eth_newPendingTransactionFilter
to initialize the filter. - Calls
eth_getFilterChanges
on a polling interval.
- Calls
- When
poll: false
& WebSocket Transport, uses a WebSocket subscription viaeth_subscribe
and the"newPendingTransactions"
event.
- When
Remarks
This Action will batch up all the pending transactions found within the pollingInterval
, and invoke them via onTransactions
.
Example
Parameters
• args: WatchPendingTransactionsParameters
<Transport
>
WatchPendingTransactionsParameters
Returns
WatchPendingTransactionsReturnType
Example
Source
packages/memory-client/src/createMemoryClient.js:40