Skip to main content
The plugin extends hre with hre.cofhe, providing three ways to create and connect a CofheClient in your Hardhat tests. 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
createClientWithBatteries generates a self-permit automatically, so most test operations (encrypting inputs, decrypting for view, decrypting for tx) work immediately without any extra setup.
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.
1

Create config

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
2

Create the client

3

Connect with a Hardhat 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:

Using the client

Once connected, the client works identically to the standard SDK client. See: