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
createClientWithBatteries generates a self-permit automatically, so most test operations (encrypting inputs, decrypting for view, decrypting for tx) work immediately without any extra setup.signer is omitted, the first signer from hre.ethers.getSigners() is used.
Manual setup
For more control — custom config options, multiple signers, or adjustingencryptDelay — you can set up the client step by step.
Create config
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