Template to kickstart a Foundry project.
The easiest way to get started is by clicking the Use this template button at the top right of this page.
If you prefer to go the CLI way:
forge init my-project --template https://github.com/MZero-Labs/foundry-templateYou may have to install the following tools to use this repository:
- Foundry to compile and test contracts
- lcov to generate the code coverage report
- slither to static analyze contracts
Install dependencies:
npm iCopy .env and write down the env variables needed to run this project.
cp .env.example .envRun the following command to compile the contracts:
npm run compileForge is used for coverage, run it with:
npm run coverageYou can then consult the report by opening coverage/index.html:
open coverage/index.htmlTo run all tests:
npm testRun test that matches a test contract:
forge test --mc <test-contract-name>Test a specific test case:
forge test --mt <test-case-name>To run slither:
npm run slitherHusky is used to run lint-staged and tests when committing.
Prettier is used to format code. Use it by running:
npm run prettierSolhint is used to lint Solidity files. Run it with:
npm run solhintTo fix solhint errors, run:
npm run solhint-fixThe following Github Actions workflow are setup to run on push and pull requests:
It will build the contracts and run the test coverage, as well as a gas report.
The coverage report will be displayed in the PR by github-actions-report-lcov and the gas report by foundry-gas-diff.
For the workflows to work, you will need to setup the MNEMONIC_FOR_TESTS and MAINNET_RPC_URL repository secrets in the settings of your Github repository.
Some additional workflows are available if you wish to add fuzz, integration and invariant tests:
- .github/workflows/test-fuzz.yml
- .github/workflows/test-integration.yml
- .github/workflows/test-invariant.yml
You will need to uncomment them to activate them.
The documentation can be generated by running:
npm run docIt will run a server on port 4000, you can then access the documentation by opening http://localhost:4000.
To compile the contracts for production, run:
npm run buildOpen a new terminal window and run anvil to start a local chain:
anvilDeploy the contracts by running:
npm run deploy-localTo deploy to the Sepolia testnet, run:
npm run deploy-sepolia