Set up a Hardhat project withDocumentation Index
Fetch the complete documentation index at: https://cofhe-docs.fhenix.zone/llms.txt
Use this file to discover all available pages before exploring further.
@cofhe/hardhat-plugin, write a contract that stores an encrypted uint32, and test the encrypt → store → decrypt flow.
Prerequisites
- Node.js 18+
- An existing Hardhat project (or run
npx hardhat initto create one) @nomicfoundation/hardhat-toolboxor@nomicfoundation/hardhat-ethersinstalled
1. Install dependencies
2. Configure Hardhat
Import the plugin and setevmVersion to cancun (required for the transient storage opcodes used by FHE contracts).
hardhat.config.ts
3. Write a contract
Create a minimal contract that accepts an encrypted input and stores it on-chain.contracts/MyContract.sol
euint32— an encrypteduint32stored on-chain as a ciphertext handle.InEuint32— the encrypted input struct produced by the SDK.FHE.allowThis/FHE.allowSender— grant the contract and caller permission to read the encrypted value (required by the ACL).
4. Write a test
Usehre.cofhe.createClientWithBatteries to get a fully configured SDK client with a self-permit, then encrypt → send → decrypt.
test/MyContract.test.ts
5. Run
What just happened?
- The Hardhat plugin deployed mock versions of the CoFHE coprocessor contracts (TaskManager, ACL, ZK verifier, threshold network) before the test ran.
createClientWithBatteriescreated an SDK client connected to the Hardhat network, with a self-permit ready to go.encryptInputsencrypted the plaintext42into an FHE ciphertext with a ZK proof (simulated by the mock verifier).- The contract stored the ciphertext handle on-chain and set ACL permissions.
decryptForViewused the permit to decrypt the handle back to42nlocally.
Next steps
- Hardhat Plugin — full plugin configuration and features.
- Mock Contracts — read plaintext directly and assert encrypted state in tests.
- Logging — inspect every FHE operation your contracts perform.