Client
The plugin extends hre with hre.cofhe, providing three ways to create and connect a CofheClient in your Hardhat tests.
Batteries included (recommended)
hre.cofhe.createClientWithBatteries(signer?) is the one-liner that handles everything:
- Creates a CoFHE config with
environment: 'hardhat'andsupportedChains: [hardhat] - Creates a
CofheClient - Connects it using the provided Hardhat signer (defaults to the first signer)
- Generates a self-usage permit for the signer
import hre from 'hardhat';
const [signer] = await hre.ethers.getSigners();
const cofheClient = await hre.cofhe.createClientWithBatteries(signer);
cofheClient.connected; // trueIf signer is omitted, the first signer from hre.ethers.getSigners() is used.
Manual setup
For more control — custom config options, multiple signers, or adjusting encryptDelay — you can set up the client step by step.
Create config
import hre from 'hardhat';
import { hardhat } from '@cofhe/sdk/chains';
const config = await hre.cofhe.createConfig({
supportedChains: [hardhat],
}); hre.cofhe.createConfig wraps createCofheConfig from @cofhe/sdk/node with two Hardhat-specific additions:
- Sets
environment: 'hardhat'automatically - Defaults
mocks.encryptDelayto0so tests run without artificial wait times
For all available config options, see Client.
Create the client
const cofheClient = hre.cofhe.createClient(config); Connect with a Hardhat signer
await hre.cofhe.connectWithHardhatSigner(cofheClient, signer); connectWithHardhatSigner uses HardhatSignerAdapter under the hood to convert a HardhatEthersSigner into the viem PublicClient + WalletClient pair that the SDK expects.
Low-level adapter
If you need direct access to the underlying viem clients, call the adapter directly:
const { publicClient, walletClient } =
await hre.cofhe.hardhatSignerAdapter(signer);
await cofheClient.connect(publicClient, walletClient);Using the client
Once connected, the client works identically to the standard SDK client. See: