Skip to content

Start with Hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Solidity smart contracts. It is an all-in-one solution that provides everything you need to build, test, deploy, and interact with smart contracts on the FAIR blockchain.

Prerequisites

Setup Project

Create Hardhat Project

The first step is to create the Hardhat project

npx hardhat --init

Configure Hardhat for FAIR

Next, you need to configure Hardhat to connect and work with the FAIR network. Update your hardhat.config.ts to include the following:

import type { HardhatUserConfig } from "hardhat/config";
 
import hardhatToolboxViemPlugin from "@nomicfoundation/hardhat-toolbox-viem";
import { configVariable } from "hardhat/config";
 
const config: HardhatUserConfig = {
  plugins: [hardhatToolboxViemPlugin],
  solidity: {
    profiles: {
      default: {
        version: "0.8.24",
      },
      production: {
        version: "0.8.24",
        settings: {
          optimizer: {
            enabled: true,
            runs: 2000,
          },
        },
      },
    },
  },
  networks: {
    "fair-testnet": {
        type: "http",
        chainType: "l1",
        url: "https://testnet-rpc.fair.cloud",
        accounts: [configVariable("PRIVATE_KEY")],
    },
    "fair-mainnet": {
      type: "http",
      chainType: "l1",
      url: "<coming-soon>",
      accounts: [configVariable("PRIVATE_KEY")],
    }
  },
};
 
export default config;

Setup Environment

Create a .env file in the root of your project and add your private key:

PRIVATE_KEY=your_private_key_here

Next Steps

Now that your project is set up, you can start building your confidential application (cApp) on FAIR! Checkout the tutorials for more examples!