Skip to main content
@cofhe/hardhat-3-plugin is the Hardhat 3 counterpart to @cofhe/hardhat-plugin. It deploys the CoFHE mock contracts to an in-process Hardhat network on every network.connect() call and exposes a cofhe namespace on the connection object — ready to use immediately, no boilerplate required.
Use this plugin if you’ve adopted the Hardhat 3 plugin/hook model. For Hardhat v2 projects, use @cofhe/hardhat-plugin instead.

What the plugin provides

  • Auto-deploys mocks on every network.connect()MockTaskManager, MockACL, MockZkVerifier, MockThresholdNetwork, and TestBed.
  • conn.cofhe namespace on the Hardhat 3 connection object (sits alongside conn.viem from @nomicfoundation/hardhat-viem).
  • cofhe.createClientWithBatteries() — one-call SDK client setup with a pre-signed self permit.
  • Mock helpers — Viem contract descriptors for every mock, plaintext inspection (getPlaintext / expectPlaintext), and logging control.

Installation

1

Install the package

2

Register the plugin

hardhat.config.ts

Configuration

The plugin adds an optional cofhe key to your Hardhat 3 config. All values shown below are their defaults:
hardhat.config.ts

How auto-deployment works

Every call to network.connect() automatically:
  1. Deploys all CoFHE mock contracts to the fresh in-process EVM.
  2. Attaches a cofhe namespace to the returned connection object.
Because network.connect() is awaitable at the top level of an async describe, you can set everything up without lifecycle hooks:
Why async describe? Hardhat 3’s node:test runner supports top-level await inside the describe callback. This lets you resolve the connection (and deploy mocks) exactly once per test file without needing a before() hook.

Mock contracts deployed

Fixed-address contracts are deployed via hardhat_setCode, so they are always at the same address regardless of deployment order. MockACL is deployed as a normal contract (so its EIP-712 domain constructor runs correctly) and its address is registered in MockTaskManager.

Differences from @cofhe/hardhat-plugin

The Solidity surface (mock contracts, plaintext semantics, FHE.verifyDecryptResult acceptance) is identical between the two plugins; the differences are all in how Hardhat hosts the plugin.

Next steps

  • Clientconn.cofhe.createConfig, createClient, createClientWithBatteries.
  • Mock Contracts — Viem contract descriptors and plaintext inspection helpers.
  • LoggingenableLogs, disableLogs, withLogs.
  • Testing — end-to-end test patterns.