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.
@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, andTestBed. conn.cofhenamespace on the Hardhat 3 connection object (sits alongsideconn.viemfrom@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
Configuration
The plugin adds an optionalcofhe key to your Hardhat 3 config. All values shown below are their defaults:
hardhat.config.ts
| Option | Type | Default | Description |
|---|---|---|---|
gasWarning | boolean | true | Print a one-line warning after mock deployment reminding that mock gas costs differ from live FHE. |
logMocks | boolean | true | Enable event-based logging inside mock contracts. |
mocksDeployVerbosity | '' | 'v' | 'vv' | 'v' | How much output to print while deploying mocks. '' silent, 'v' one summary line per mock, 'vv' full per-contract deployment log. |
How auto-deployment works
Every call tonetwork.connect() automatically:
- Deploys all CoFHE mock contracts to the fresh in-process EVM.
- Attaches a
cofhenamespace to the returned connection object.
network.connect() is awaitable at the top level of an async describe, you can set everything up without lifecycle hooks:
Mock contracts deployed
| Contract | Address | Description |
|---|---|---|
MockTaskManager | 0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9 | Coordinates FHE operations and ACL |
MockACL | dynamic | Access Control List — address resolved from TaskManager |
MockZkVerifier | 0x0000000000000000000000000000000000005001 | Verifies ZK proofs for encrypted inputs |
MockThresholdNetwork | 0x0000000000000000000000000000000000005002 | Simulates the threshold decryption network |
TestBed | 0x0000000000000000000000000000000000005003 | Utility contract for storing and retrieving encrypted values in tests |
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
| Concern | @cofhe/hardhat-plugin (v2) | @cofhe/hardhat-3-plugin |
|---|---|---|
| Entry point | hre.cofhe (global) | conn.cofhe (per network.connect() call) |
| Lifecycle | Pre-task hook (npx hardhat test / node) | network.connect() returns a fresh deployment |
| Test runner expectation | Mocha-style (before, it) | node:test with async describe |
| Mock compilation for custom-error decoding | Overrides TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS | Runs hre.solidity.build() during the hre.created hook |
| Bytecode sourcing | hre.artifacts.readArtifact() | hre.artifacts.readArtifact() (same — for variable-address mocks like MockACL) |
FHE.verifyDecryptResult acceptance) is identical between the two plugins; the differences are all in how Hardhat hosts the plugin.
Next steps
- Client —
conn.cofhe.createConfig,createClient,createClientWithBatteries. - Mock Contracts — Viem contract descriptors and plaintext inspection helpers.
- Logging —
enableLogs,disableLogs,withLogs. - Testing — end-to-end test patterns.