A Foundry-based template for developing Solidity smart contracts, with sensible defaults.
- Forge: compile, test, fuzz, format, and deploy smart contracts
- Forge Std: collection of helpful contracts and utilities for testing
- Prettier: code formatter for non-Solidity files
- Solhint: linter for Solidity code
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:
$ mkdir my-project
$ cd my-project
$ forge init --template PaulRBerg/foundry-template
$ bun install # install Solhint, Prettier, and other Node.js deps
If this is your first time with Foundry, check out the installation instructions.
This template builds upon the frameworks and libraries mentioned above, so please consult their respective documentation for details about their specific features.
For example, if you're interested in exploring Foundry in more detail, you should look at the Foundry Book. In particular, you may be interested in reading the Writing Tests tutorial.
This template comes with a set of sensible default configurations for you to use. These defaults can be found in the following files:
├── .editorconfig
├── .gitignore
├── .prettierignore
├── .prettierrc.yml
├── .solhint.json
├── foundry.toml
└── remappings.txt
This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode alongside Nomic Foundation'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.
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.
bun install dependency-name
- Use this syntax to install from GitHub:
bun 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 OpenZeppelin Contracts is pre-installed, so you can follow that as an example.
To write a new test contract, you start by importing Test
from forge-std
, and then you inherit it in your test
contract. Forge Std comes with a pre-instantiated cheatcodes environment
accessible via the vm
property. If you would like to view the logs in the terminal output, you can add the -vvv
flag
and use console.log.
This template comes with an example test contract Foo.t.sol
This is a list of the most frequently needed commands.
Build the contracts:
$ forge build
Delete the build artifacts and cache directories:
$ forge clean
Compile the contracts:
$ forge build
Get a test coverage report:
$ forge coverage
Deploy to Anvil:
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545
For this script to work, you need to have a MNEMONIC
environment variable set to a valid
BIP39 mnemonic.
For instructions on how to deploy to a testnet or mainnet, check out the Solidity Scripting tutorial.
Format the contracts:
$ forge fmt
Get a gas report:
$ forge test --gas-report
Lint the contracts:
$ bun run lint
Run the tests:
$ forge test
Generate test coverage and output result to the terminal:
$ bun run test:coverage
Generate test coverage with lcov report (you'll have to open the ./coverage/index.html
file in your browser, to do so
simply copy paste the path):
$ bun run test:coverage:report
- abigger87/femplate
- cleanunicorn/ethereum-smartcontract-template
- foundry-rs/forge-template
- FrankieIsLost/forge-template
This project is licensed under MIT.
l1Registry: contract ERC6551L1Registry 0x0D359070f6528E8f8bf8C373Ac80567A4449B5A3 nft: contract MockNFT 0x2643cD7c2BD7364d3778495CC910e0Cd41d44602 sender: contract CCIPERC6551Sender 0x35eE77607d9466E75072f62D58683Bb697eB2181
l2Registry: contract ERC6551L2Registry 0x2DdcF338F75FbDB3F4B9239976F4a36E7f93c1AC receiver: contract CCIPERC6551Receiver 0xde627cDeD2A7241B1f3679821588dB42B62f7699 counter: contract Counter 0x6f719490dEC688b8C7c394f5259aE5AA788C3a5D
https://ccip.chain.link/msg/0x5a693b26e3ff913748b3b07b28963baf20817b9257d08760689574e210198aea