This repo contains the basic files and configuration of a Hardhat-Foundry hybrid development framework. You can simply start a project with Hardhat and Foundry.
If this is your first time with Foundry, check out the installation instructions.
The initial directory structure looks like:
$ tree . -d -L 1
.
├── deploy
├── src
└── test
In this template, I configured several formatter and code analyzer in advanced to enhance the coding style for collaborative work: eslint for typescript files, solhint for solidity files, and prettier for all. Furthermore, I also configured cspell to avoid typo in coding.
Foundry is responsible for solidity-based test while Hardhat is used to complete deployment of contracts.
- Solidity-based test:
- Testing files are placed in
./test
. - NOTICE: Due to the design in
hardhat.config.ts
, all testing files should end with.t.sol
.
- Testing files are placed in
- Contract Source Code:
./src
- Deployment:
./deploy
is the contract deployment script path.
Foundry typically uses git submodules to manage dependencies, but this template uses Node.js packages because submodules don't scale.
This is how to install dependencies:
- Install the dependency using your preferred package manager, e.g.
npm install dependency-name
- Use this syntax to install from GitHub:
npm install github:username/repo-name
- Use this syntax to install from GitHub:
- Add a remapping for the dependency in remappings.txt, e.g.
dependency-name=node_modules/dependency-name
Note that forge-std Contracts is pre-installed, so you can follow that as an example.
Build / Compile the contracts:
$ forge build
Delete the build artifacts and cache directories:
$ forge clean
Get a test coverage report:
$ forge coverage
Generate typechain (by hardhat):
$ npx hardhat compile
Deploy:
$ npx hardhat --network <network> deploy <tag>
Format the contracts:
$ forge fmt
Get a gas report:
$ forge test --gas-report
Run the tests:
$ forge test
Run the tests with detailed report:
$ forge test -vvvv
Verify contracts:
$ ETHERSCAN_API_KEY=<etherscan_api_key> forge verify-contract --watch --compiler-version "v0.8.23" \
[--verifier-url http://localhost:5000] \
--constructor-args $(cast abi-encode "constructor(string)" "string") \
<address> Some-contract