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.

Hardhat

Getting Started

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

Install the following prerequisites:

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!

info

OpenZeppelin version 4.x is used for this Starter Kit, ensure you refer to the correct version of the OpenZeppelin documentation.

Setup

Cloning and installing dependencies

Clone the template repository and navigate into the project directory.

git clone https://github.com/flare-foundation/flare-hardhat-starter.git
cd flare-hardhat-starter

Install the project dependencies.

npm install

Setting up environment variables

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

cp .env.example .env

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

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.

Testing your contracts

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

npx hardhat test

Deploying your contracts

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

Foundry

Getting Started

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

Install the following prerequisites:

Setup

Cloning and installing dependencies

Clone the template repository and navigate into the project directory.

git clone https://github.com/flare-foundation/flare-foundry-starter.git
cd flare-foundry-starter

Install the project dependencies.

forge install

Setting up environment variables

Add PRIVATE_KEY to your environment variables.

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

Compile the smart contracts to generate the necessary artifacts.

forge build

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

Testing contracts

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

forge test

Deploying your contracts

Run the deployment script using Foundry:

forge script script/Counter.s.sol --broadcast --private-key $PRIVATE_KEY --rpc-url <RPC_URL>

Replace <RPC_URL> with the RPC endpoint of the network you are deploying to. A list of RPC endpoints for Flare networks can be found in Flare's Network Configuration.