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.
yarnor alternatively:
npm install --force -
Copy the example environment file and update it with your settings.
cp .env.example .env -
Open the
.envfile and set yourPRIVATE_KEY.PRIVATE_KEY=your_private_key_heredanger- 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.
make installThe
make installtarget runsforge soldeer installand additionally fetches the npm-only dependencies (ftso-adapters,pyth-sdk-solidity,lz-address-book) used by the starter's adapter and OFT examples. -
The starter ships with a
remappings.txtready for the current periphery release.
For reference, it contains:
@openzeppelin-contracts/=dependencies/@openzeppelin-contracts-5.2.0-rc.1/
flare-periphery/=dependencies/flare-periphery-0.1.37/
@flarenetwork/flare-periphery-contracts/=dependencies/flare-periphery-0.1.37/src/
forge-std/=dependencies/forge-std-1.9.5/src/
surl/=dependencies/surl-0.0.0/src/
surl/=dependencies/surl-0.0.0/
lz-address-book/=dependencies/lz-address-book/src/
@layerzerolabs/lz-evm-protocol-v2/=dependencies/lz-address-book/lib/LayerZero-v2/packages/layerzero-v2/evm/protocol/
@layerzerolabs/lz-evm-messagelib-v2/=dependencies/lz-address-book/lib/LayerZero-v2/packages/layerzero-v2/evm/messagelib/
@layerzerolabs/oft-evm/=dependencies/lz-address-book/lib/devtools/packages/oft-evm/
@layerzerolabs/oapp-evm/=dependencies/lz-address-book/lib/devtools/packages/oapp-evm/
solidity-bytes-utils/=dependencies/lz-address-book/lib/solidity-bytes-utils/
solady/=dependencies/solady-0.1.26/
ftso-adapters/=dependencies/ftso-adapters-0.0.1/
@pythnetwork/pyth-sdk-solidity/=dependencies/pyth-sdk-solidity-2.2.0/
-
Copy
.env.exampleto.envand update it with your settings.Add
PRIVATE_KEYto your environment variables.PRIVATE_KEY=your_private_key_heredanger- 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
.envfile to your bash profile:source .envYou need to do this every time you open a new terminal or change the
.envfile.
Compile, test and deploy
- Hardhat
- Foundry
-
Compile the smart contracts to generate the necessary artifacts.
yarn hardhat compileor alternatively:
yarn hardhat compileThis command compiles all
.solfiles in the/contractsfolder and generates artifacts needed for testing. -
Run the provided test suite to ensure everything is set up correctly.
yarn hardhat testor alternatively:
yarn hardhat test -
Review and modify
hardhat.config.tsto 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 Flare Explorer in the .env file.
yarn hardhat run scripts/tryDeployment.ts
or alternatively:
yarn hardhat run scripts/tryDeployment.ts --network coston2
Congratulations!
You have successfully integrated Flare into Hardhat.
-
Compile the smart contracts to generate the necessary artifacts.
forge buildThis command compiles all
.solfiles in the/srcfolder 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/HelloWorld.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.