Set up Hardhat

In this section, you’ll learn how to set up a FHEVM Hardhat development environment using the FHEVM Hardhat template as a starting point for building and testing fully homomorphic encrypted smart contracts.

Create a local Hardhat Project

1

Install a Node.js TLS version

Ensure that Node.js is installed on your machine.

  • Download and install the recommended LTS (Long-Term Support) version from the official websitearrow-up-right.

  • Use an even-numbered version (e.g., v18.x, v20.x)

circle-exclamation

To verify your installation:

node -v
npm -v
2

Create a new GitHub repository from the FHEVM Hardhat template.

  1. On GitHub, navigate to the main page of the FHEVM Hardhat templatearrow-up-right repository.

  2. Above the file list, click the green Use this template button.

  3. Follow the instructions to create a new repository from the FHEVM Hardhat template.

3

Clone your newly created GitHub repository locally

Now that your GitHub repository has been created, you can clone it to your local machine:

cd <your-preferred-location>
git clone <url-to-your-new-repo>

# Navigate to the root of your new FHEVM Hardhat project
cd <your-new-repo-name>

Next, let’s install your local Hardhat development environment.

4

Install your FHEVM Hardhat project dependencies

From the project root directory, run:

npm install

This will install all required dependencies defined in your package.json, setting up your local FHEVM Hardhat development environment.

5

Set up the Hardhat configuration variables (optional)

If you do plan to deploy to the Sepolia Ethereum Testnet, you'll need to set up the following Hardhat Configuration variablesarrow-up-right.

MNEMONIC

A mnemonic is a 12-word seed phrase used to generate your Ethereum wallet keys.

  1. Get one by creating a wallet with MetaMaskarrow-up-right, or using any trusted mnemonic generator.

  2. Set it up in your Hardhat project:

npx hardhat vars set MNEMONIC

INFURA_API_KEY

The INFURA project key allows you to connect to Ethereum testnets like Sepolia.

  1. Obtain one by following the Infura + MetaMaskarrow-up-right setup guide.

  2. Configure it in your project:

npx hardhat vars set INFURA_API_KEY

Default Values

If you skip this step, Hardhat will fall back to these defaults:

  • MNEMONIC = "test test test test test test test test test test test junk"

  • INFURA_API_KEY = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

circle-exclamation
circle-exclamation

Missing variable error:

Congratulations! You're all set to start building your confidential dApp.

Optional settings

Install VSCode extensions

If you're using Visual Studio Code, there are some extensions available to improve you your development experience:

Solidity support (pick one only):

Reset the Hardhat project

If you'd like to start from a clean slate, you can reset your FHEVM Hardhat project by removing all example code and generated files.

Then run:

Last updated