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:
- Creates a config for the Hardhat mock environment, with
supportedChains: [hardhat]and a zeromocks.encryptDelay. - Creates the client and connects it with the connection’s public client and your wallet client.
- Signs a self ACP (Access Control Permission) for the wallet’s address and makes it the active ACP.
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-zeroencryptDelay.
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
client.connected is false.3
Connect it
connect takes viem clients directly, so the clients from @nomicfoundation/hardhat-viem pass straight in.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.InvalidSigner, which viem reports as the selector 0x7ba5ffb5.