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
- Hardhat
- Foundry
If you're new to Hardhat, review Hardhat's documentation on Getting Started with Hardhat.
Install the following tools:
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!
If you're new to Foundry, review Foundry's documentation on Getting Started with Foundry.
Install the following tools:
Clone the template
- Hardhat
- Foundry
-
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 -
Install the project dependencies.
npm install
-
Copy the example environment file and update it with your settings.
cp .env.example .env
-
Open the
.env
file and set yourPRIVATE_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.
-
Clone the flare-foundry-starter 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 soldeer install
-
You might need to modify
remappings.txt
so/src
paths are read correctly, e.g.:@openzeppelin-contracts/=dependencies/@openzeppelin-contracts-5.2.0-rc.1/
flare-periphery/=dependencies/flare-periphery-0.0.1/
forge-std/=dependencies/forge-std-1.9.5/src/
forge-std/=dependencies/forge-std-1.9.5/
surl/=dependencies/surl-0.0.0/src/
surl/=dependencies/surl-0.0.0/ -
Copy
.env.example
to.env
and update it with your settings.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.
-
You now need to add the information from the
.env
file to your bash profile:source .env
You need to do this every time you open a new terminal or change the
.env
file.
Compile, test and deploy
- Hardhat
- Foundry
-
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. -
Run the provided test suite to ensure everything is set up correctly.
npx hardhat test
-
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.
-
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. -
Run the provided test suite to ensure everything is set up correctly.
forge test
-
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.
Congratulations! You have successfully integrated Flare into Foundry.