Skip to main content

Hardhat and Foundry Starter Kit

The starter kit includes a basic setup for configuring Hardhat and Foundry, along with examples on how to compile, test and deploy smart contracts on Flare.

Prerequisites

If you're new to Hardhat, review Hardhat's documentation on Getting Started with Hardhat.

Install the following tools:

tip

Hardhat for Visual Studio Code is the official Hardhat extension that adds advanced support for Solidity to VSCode. If you use VSCode, give it a try!

Clone the template

  1. Clone the flare-hardhat-starter and navigate into the project directory.

    git clone https://github.com/flare-foundation/flare-hardhat-starter.git
    cd flare-hardhat-starter
  2. Install the project dependencies.

    npm install
  3. Copy the example environment file and update it with your settings.

    cp .env.example .env
  4. Open the .env file and set your PRIVATE_KEY.

    PRIVATE_KEY=your_private_key_here
    danger
    • Never share your private keys.
    • Never put your private keys in source code.
    • Never commit private keys to a Git repository.

Compile, test and deploy

  1. Compile the smart contracts to generate the necessary artifacts.

    npx hardhat compile

    This command compiles all .sol files in the /contracts folder and generates artifacts needed for testing.

  2. Run the provided test suite to ensure everything is set up correctly.

    npx hardhat test
  3. Review and modify hardhat.config.ts to specify the networks you want to deploy to. The details for Flare Mainnet, Flare Testnet Coston2, Songbird Canary-Network and Songbird Testnet Coston are already included.

Optionally you can add the API keys for either Flarescan or Flare Explorer in the .env file.

npx hardhat run scripts/tryDeployment.ts

Congratulations! You have successfully integrated Flare into Hardhat.