Skip to content

Lesson 2: Environment Setup

Duration: ~30 minutes | Prerequisites: Lesson 1: FHE Theory | Code: Configuration only


Learning Objectives

By the end of this lesson, you will:

  • Have a Hardhat workspace configured for FHEVM development
  • Understand the repo structure and how Hardhat compiles the bootcamp contracts
  • Know how local mock mode works in the official plugin flow
  • Successfully run npm run compile and npm test

1. Install Node.js

Hardhat requires Node.js. Use an even-numbered LTS release such as Node 20.

bash
node -v
npm -v

2. Clone and Install

bash
git clone --recurse-submodules https://github.com/0xNana/fhevm-bootcamp.git
cd fhevm-bootcamp
npm install

3. Compile the Contracts

bash
npm run compile

The project targets:

  • Solidity 0.8.27
  • EVM version cancun
  • Optimizer enabled with 800 runs

4. Project Structure

text
fhevm-bootcamp/
├── contracts/                # Hardhat entrypoints
├── src/                      # Solution contracts
├── starter/                  # Homework starter contracts
├── test/
│   ├── helpers/              # Shared FHEVM helpers
│   ├── solutions/            # Solution suites
│   └── starter/              # Homework suites
├── deploy/                   # hardhat-deploy scripts
├── hardhat.config.ts         # Hardhat + FHEVM plugin configuration
└── package.json              # Scripts and dependencies

The source files students read and edit stay in src/ and starter/. The contracts/ directory exists so Hardhat can compile those same contracts without changing the teaching layout.

5. How Mock Mode Works

On the default hardhat network, the FHEVM plugin runs in an in-memory mock mode. That gives you:

  • encrypted input creation through fhevm.createEncryptedInput(...)
  • encrypted value decryption through the Hardhat runtime
  • fast local feedback without a live FHEVM network

This is the same development model Zama documents for early encrypted-contract testing.

6. The Core Hardhat Test Loop

ts
const encryptedOne = await fhevm
  .createEncryptedInput(counterAddress, alice.address)
  .add32(1)
  .encrypt();

await counter.connect(alice).increment(encryptedOne.handles[0], encryptedOne.inputProof);

const clearCount = await fhevm.userDecryptEuint(
  FhevmType.euint32,
  await counter.getCount(),
  counterAddress,
  alice,
);

That loop is the foundation for the rest of the bootcamp:

  1. Encrypt a value for a specific contract and signer.
  2. Submit the encrypted handle and proof to the contract.
  3. Decrypt the result from a signer that has permission.

7. Run the Tests

bash
npm test

You can also run individual weeks:

bash
npm run test:week1
npm run test:starter:week1

Key Takeaways

  1. The official Hardhat plugin is the main local development entrypoint.
  2. Mock mode lets you exercise encrypted flows without real FHE infrastructure.
  3. The repo structure keeps lesson code separate from Hardhat entrypoints.
  4. The same contract code later deploys to Sepolia with a different runtime.

Next: Lesson 3: Hello FHE — Your First Encrypted Contract.

Built for the Zama Developer Program — Bounty Track