Skip to main content
Every network connection carries a cofhe object with three methods for building a CofheClient. Use createClientWithBatteries in most tests, and the manual path when you need to change the client config. The examples on this page run inside an async describe callback that opens a connection first:

Batteries included

cofhe.createClientWithBatteries(walletClient?) returns a client that is ready to encrypt and decrypt. It:
  1. Creates a config for the Hardhat mock environment, with supportedChains: [hardhat] and a zero mocks.encryptDelay.
  2. Creates the client and connects it with the connection’s public client and your wallet client.
  3. Signs a self ACP (Access Control Permission) for the wallet’s address and makes it the active ACP.
Called with no argument, it signs with the first account of the connection:
Because the self ACP exists from the start, decryptForView and decryptForTx().withACP() work without any further setup.

Manual setup

Build the client step by step when a test needs a different config, for example a non-zero encryptDelay.
1

Create the config

cofhe.createConfig wraps createCofheConfig from @cofhe/sdk/node. It sets environment: 'hardhat' and supportedChains: [hardhat], defaults mocks.encryptDelay to 0, and merges your overrides on top.
2

Create the client

The client is not connected yet: client.connected is false.
3

Connect it

connect takes viem clients directly, so the clients from @nomicfoundation/hardhat-viem pass straight in.
A manually built client also creates a self ACP when it connects, so decryptForView works without extra setup here too.

Several signers

Create one client per wallet. Each client signs its own encrypted inputs and holds its own ACP.
An encrypted input is bound to the account that encrypted it. Send the transaction from that same wallet, or the contract reverts with InvalidSigner, which viem reports as the selector 0x7ba5ffb5.

API summary

Using the client

Once connected, the client is the standard SDK client. See: