Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

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:

  1. Creates a CoFHE config with environment: 'hardhat' and supportedChains: [hardhat]
  2. Creates a CofheClient
  3. Connects it using the provided Hardhat signer (defaults to the first signer)
  4. 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; // true

If 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.encryptDelay to 0 so 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: