Skip to content
On this page

Test Client

The createTestClient function sets up a Test RPC Client with a given Transport.

The Test RPC Client provides access to Test Actions.

Import

ts
import { createTestClient } from 'viem'

Usage

Initialize a Client with your desired Chain, Transport (e.g. http) and mode (e.g. "anvil").

ts
import { createTestClient, http } from 'viem'
import { foundry } from 'viem/chains'

const client = createTestClient({
  chain: foundry,
  mode: 'anvil',
  transport: http(), 
})

Parameters

mode

  • Type: "anvil" | "hardhat"

Mode of the Test Client.

ts
const client = createTestClient({
  chain: foundry,
  mode: 'anvil', 
  transport: http(), 
})

transport

Transport of the Test Client.

ts
const client = createTestClient({
  chain: foundry,
  mode: 'anvil', 
  transport: http(),  
})

chain (optional)

Chain of the Test Client.

ts
const client = createTestClient({
  chain: foundry, 
  mode: 'anvil',
  transport: http(), 
})

name (optional)

  • Type: string
  • Default: "Test Client"

A name for the Client.

ts
const client = createTestClient({
  chain: foundry,
  mode: 'anvil', 
  name: 'Anvil Client',  
  transport: http(),
})

pollingInterval (optional)

  • Type: number
  • Default: 4_000

Frequency (in ms) for polling enabled Actions.

ts
const client = createTestClient({
  chain: foundry,
  mode: 'anvil', 
  pollingInterval: 10_000,  
  transport: http(),
})

Released under the MIT License.