Foundry-based template for developing Solidity smart contracts used by Vac
Go to file
Paul Razvan Berg c333dd8213
chore: run "forge fmt" on every commit
docs: update README with latest setup
2023-02-16 13:00:36 +02:00
.github ci: add missing Foundry install 2023-02-07 20:10:50 +02:00
.vscode feat: add "even-better-toml" in VSCode settings 2023-01-26 13:19:46 +02:00
.yarn build: upgrade to Yarn v3.4.1 2023-02-07 19:59:19 +02:00
lib build: pin "prb-math" submodule to "v3" branch 2023-02-08 22:42:48 +02:00
script refactor: use mnemonic in deployment script 2023-02-07 14:10:42 +02:00
src feat: add identity function "id" in "Foo" contract 2023-02-07 14:10:43 +02:00
test refactor: change pragma to ">=0.8.18" 2023-02-07 14:10:42 +02:00
.commitlintrc.yml feat: initial commit 2022-07-17 21:57:09 +03:00
.editorconfig chore: fix indenting for *.sol in .editorconfig 2022-09-15 00:57:35 +02:00
.env.example test: add Ethereum Mainnet fork test 2023-01-17 19:49:14 +02:00
.gitignore chore: unignore html files 2023-02-08 10:57:56 +02:00
.gitmodules build: pin "prb-math" submodule to "v3" branch 2023-02-08 22:42:48 +02:00
.lintstagedrc.yml chore: run "forge fmt" on every commit 2023-02-16 13:00:36 +02:00
.prettierignore feat: initial commit 2022-07-17 21:57:09 +03:00
.prettierrc.yml style: add "tabWidth" Prettier override for Solidity 2023-01-19 16:18:22 +02:00
.solhint.json refactor: change pragma to ">=0.8.18" 2023-02-07 14:10:42 +02:00
.solhintignore feat: initial commit 2022-07-17 21:57:09 +03:00
.yarnrc.yml build: upgrade to Yarn v3.4.1 2023-02-07 19:59:19 +02:00
LICENSE.md chore: update copyright year in license 2023-01-01 13:26:12 +02:00
README.md chore: run "forge fmt" on every commit 2023-02-16 13:00:36 +02:00
foundry.toml chore: run "forge fmt" on every commit 2023-02-16 13:00:36 +02:00
package.json chore: run "forge fmt" on every commit 2023-02-16 13:00:36 +02:00
remappings.txt chore: add "src" to remappings 2022-11-20 16:34:27 +02:00
yarn.lock build: upgrade Node.js deps 2023-02-11 13:14:43 +02:00

README.md

Foundry Template Open in Gitpod Github Actions Foundry License: MIT

A Foundry-based template for developing Solidity smart contracts, with sensible defaults.

What's Inside

  • Forge: compile, test, fuzz, format, and deploy smart contracts
  • PRBTest: modern collection of testing assertions and logging utilities
  • Forge Std: collection of helpful contracts and cheatcodes for testing
  • Solhint: linter for Solidity code
  • Prettier Plugin Solidity: code formatter for non-Solidity files

Getting Started

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/PaulRBerg/foundry-template
cd my-project
yarn install # install Solhint, Prettier, and other tools

If this is your first time with Foundry, check out the installation instructions.

Features

This template builds upon the frameworks and libraries mentioned above, so for details about their specific features, please consult their respective documentation.

For example, for Foundry, you can refer to the Foundry Book. You might be in particular interested in reading the Writing Tests guide.

Sensible Defaults

This template comes with sensible default configurations in the following files:

├── .commitlintrc.yml
├── .editorconfig
├── .gitignore
├── .lintstagedrc.yml
├── .prettierignore
├── .prettierrc.yml
├── .solhintignore
├── .solhint.json
├── .yarnrc.yml
├── foundry.toml
└── remappings.txt

VSCode Integration

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.

GitHub Actions

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.

Conventional Commits

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.

Git Hooks

This template uses Husky to run automated checks on commit messages, and Lint Staged to automatically format the code with Forge and Prettier when making a git commit.

Writing Tests

To write a new test contract, you start by importing PRBTest and inherit from it in your test contract. PRBTest 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 -vvv flag.

This template comes with an example test contract Foo.t.sol.

Usage

Here's a list of the most frequently needed commands.

Build

Build the contracts:

$ forge build

Clean

Delete the build artifacts and cache directories:

$ forge clean

Compile

Compile the contracts:

$ forge build

Coverage

Get a test coverage report:

$ forge coverage

Deploy

Deploy to Anvil:

$ forge script script/DeployFoo.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

Format the contracts:

$ forge fmt

Gas Usage

Get a gas report:

$ forge test --gas-report

Lint

Lint the contracts:

$ yarn lint

Test

Run the tests:

$ forge test

Notes

  1. Foundry piggybacks off git submodules to manage dependencies. There's a guide about how to work with dependencies in the book.
  2. 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.

License

MIT © Paul Razvan Berg