Skip to main content

Documentation Index

Fetch the complete documentation index at: https://fhenix-docs-hardhat-3-plugin.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

The plugin extends every Hardhat 3 connection with a cofhe namespace. There are three ways to create and connect a CofheClient from a test, in increasing order of control. cofhe.createClientWithBatteries(walletClient?) is the one-call setup. It:
  1. Creates a CoFHE config with environment: 'hardhat'.
  2. Creates a CofheClient.
  3. Connects it using the wallet client you pass (or the first wallet client on the connection if you don’t).
  4. Generates and signs a self permit so the client can immediately decrypt encrypted values.
import { describe, it } from 'node:test';
import { network } from 'hardhat';

describe('My FHE contract', async () => {
  const { viem, cofhe } = await network.connect();
  const [walletClient] = await viem.getWalletClients();

  it('decrypts a value', async () => {
    const client = await cofhe.createClientWithBatteries(walletClient);
    client.connected; // true
  });
});
Or call it with no arguments to use the first wallet client on the connection:
const client = await cofhe.createClientWithBatteries();
Because the self permit is created up-front, encrypt / decrypt / decryptForView / decryptForTx all work immediately without any additional setup.

Manual setup

For more control — custom config options, multiple signers, adjusting encryptDelay — set up the client step by step.
1

Create config

const config = await cofhe.createConfig();
// With overrides:
const config = await cofhe.createConfig({ mocks: { encryptDelay: 0 } });
cofhe.createConfig wraps createCofheConfig from @cofhe/sdk/node with two Hardhat-3-specific additions:
  • Sets environment: 'hardhat' automatically.
  • Defaults mocks.encryptDelay to 0 so tests run without artificial wait times.
2

Create the client

const client = cofhe.createClient(config);
The client is not connected yet — call client.connect(...) before using it.
3

Connect with the connection's wallet client

const publicClient = await viem.getPublicClient();
const [walletClient] = await viem.getWalletClients();

await client.connect(publicClient, walletClient);

API summary

MethodReturnsDescription
cofhe.createConfig(overrides?)Promise<CofheConfig>CoFHE config pre-wired for the Hardhat mock environment (environment: 'hardhat', mocks.encryptDelay: 0).
cofhe.createClient(config)CofheClientUnconnected client. Call client.connect(publicClient, walletClient) before use.
cofhe.createClientWithBatteries(walletClient?)Promise<CofheClient>Fully configured + connected + self-permit signed. Defaults to the first wallet client on the connection.

Using the client

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