Skip to content

Latest commit

 

History

History
 
 

next-hardhat

Noir with Next and Hardhat

Netlify Status

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.

Getting Started

  1. Install yarn (tested on yarn v1.22.19)

  2. Install Node.js ≥v18 (tested on v18.17.0)

  3. Install noirup with

    curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
  4. Install Nargo v0.10.1 with

    noirup -v 0.10.1
  5. Install dependencies with

    yarn
  6. Navigate to the circuits directory with

    cd circuits
  7. Write your Noir program in ./circuits/src.

    Note: You can read more about writing Noir programs in the Noir docs.

  8. Generate the verifier contract with

    nargo codegen-verifier
  9. Compile your Noir program with

    nargo compile
  10. Navigate back into the next-hardhat directory with

    cd ..

Test locally

  1. Copy next-hardhat/.env.example to a new file next-hardhat/.env.

  2. Start a local development EVM at http://localhost:8545 with

    npx hardhat node

    or if foundry is preferred, with

    anvil
  3. Run the example test file with

    yarn test

The test demonstrates basic usage of Noir in a TypeScript Node.js environment.

Deploy locally

  1. Copy next-hardhat/.env.example to a new file next-hardhat/.env.

  2. Start a local development EVM at http://localhost:8545 with

    npx hardhat node

    or if foundry is preferred, with

    anvil
  3. 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 with yarn.

  4. Once your contracts are deployed and the build is finished, start the web app with

    yarn start

Deploy on networks

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