@cofhe/hardhat-plugin, write a contract that stores an encrypted uint32, and test the encrypt to store to 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 onchain.contracts/MyContract.sol
euint32: an encrypteduint32stored onchain as a ciphertext handle.externalEuint32: the encrypted input handle produced by the SDK, paired with abytesproof.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-ACP, then encrypt to send to 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-ACP ready to go.encryptInputsencrypted the plaintext42into an FHE ciphertext with a ZK proof (simulated by the mock verifier).- The contract stored the ciphertext handle onchain and set ACL permissions.
decryptForViewused the ACP 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.