A lightning-fast Foundry template for Solidity smart contract development.
- Forge: compile, test, fuzz, debug and deploy smart contracts
- Forge Std: collection of helpful contracts and cheatcodes for testing
Click the Use this template
button at the top of the page to
create a new repository with this repo as the initial state.
Or, if you prefer to install the template manually:
forge init my-project --template https://github.com/hifi-finance/foundry-template
cd my-project
make
This project was built using Foundry. Refer to installation instructions here.
This template builds upon the frameworks and libraries mentioned above, so for details about their specific features, please consult their respective documentations.
For example, for Foundry, you can refer to the Foundry Book. You might be in particular interested in reading the Writing Tests guide.
This template comes with sensible default configurations in the following files:
├── .commitlintrc.yaml
├── .gitattributes
├── .gitignore
├── .gitmodules
├── .pre-commit-config.yaml
├── foundry.toml
├── makefile
└── remappings.txt
This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode with Juan Blanco's Solidity extension.
For guidance on how to integrate a Foundry project in VSCode, please refer to this guide.
This template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull
request made to the main
branch.
You can edit the CI script in .github/workflows/ci.yml.
This template enforces the Conventional Commits standard for git commit messages. This is a lightweight convention that creates an explicit commit history, which makes it easier to write automated tools on top of.
To write a new test contract, you start by importing DSTest and inherit from
it in your test contract. DSTest comes with a pre-instantiated cheatcodes
environment accessible via the vm
property. You can also use
console.log, whose logs you can see in
the terminal output by adding the -vvvv
flag.
This template comes with an example test contract Foo.t.sol.
To make it easier to perform some tasks within the repo, a few commands are available through a makefile:
Command | Action |
---|---|
make build |
Compile all contracts in the repo, including submodules. |
make clean |
Delete the build artifacts and cache directories. |
make fmt-check |
Lint the contracts. |
make fmt-write |
Format the contracts. |
Command | Description |
---|---|
make coverage |
Get a test coverage report. |
make test |
Run all tests located in tests/ . |
make gas-report |
Get a gas report. |
Specific tests can be run using forge test
conventions, specified in more detail in the Foundry Book.
Command | Description |
---|---|
make deploy |
Deploy to Anvil. |
For instructions on how to deploy to a testnet or mainnet, check out the Solidity Scripting tutorial.
- Foundry piggybacks off git submodules to manage dependencies. There's a guide about how to work with dependencies in the book.
- You don't have to create a
.env
file, but filling in the environment variables may be useful when debugging and testing against a mainnet fork.
- PaulRBerg/foundry-template
- ScopeLift/foundry-template
- abigger87/femplate
- cleanunicorn/ethereum-smartcontract-template
- foundry-rs/forge-template
- FrankieIsLost/forge-template
MIT © Mainframe Group Inc.