This example uses Next.js as the frontend framework, and Hardhat to deploy and test.
It also features multiple files and different entry points by resolving multiple files and using the
entry_point
parameter to the compile
function.
-
Install yarn (tested on yarn v1.22.19)
-
Install Node.js ≥v18 (tested on v18.17.0)
-
Install noirup with
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
-
Install Nargo v0.10.1 with
noirup -v 0.10.1
-
Install dependencies with
yarn
-
Navigate to the circuits directory with
cd circuits
-
Write your Noir program in
./circuits/src
.Note: You can read more about writing Noir programs in the Noir docs.
-
Generate the verifier contract with
nargo codegen-verifier
-
Compile your Noir program with
nargo compile
-
Navigate back into the next-hardhat directory with
cd ..
-
Copy
next-hardhat/.env.example
to a new filenext-hardhat/.env
. -
Start a local development EVM at http://localhost:8545 with
npx hardhat node
or if foundry is preferred, with
anvil
-
Run the example test file with
yarn test
The test demonstrates basic usage of Noir in a TypeScript Node.js environment.
-
Copy
next-hardhat/.env.example
to a new filenext-hardhat/.env
. -
Start a local development EVM at http://localhost:8545 with
npx hardhat node
or if foundry is preferred, with
anvil
-
Build the project and deploy contracts to the local development chain with
NETWORK=localhost yarn build
Note: If the deployment fails, try removing
yarn.lock
and reinstalling dependencies withyarn
. -
Once your contracts are deployed and the build is finished, start the web app with
yarn start
You can choose any other network in hardhat.config.ts
and deploy there using this NETWORK
environment variable.
For example, NETWORK=mumbai yarn build
or NETWORK=sepolia yarn build
.
Make sure you:
- Update the deployer private keys in
next-hardhat/.env
- Have funds in the deployer account
- Add keys for alchemy (to act as a node) in
next-hardhat/.env
Feel free to contribute with other networks in hardhat.config.ts