Foundry-based template for developing Solidity smart contracts used by Vac
Go to file
Paul Razvan Berg ab14bc361d
chore: add "src" to remappings
The goal is to make paths work with VSCode's "Go to Definition"
2022-11-20 16:34:27 +02:00
.github ci: use LTS version in CI script 2022-10-15 22:30:41 +03:00
.yarn build: upgrade to yarn v3.2.4 2022-10-30 18:39:19 +02:00
lib build: upgrade to prb-test v0.1.3 2022-10-29 16:37:43 +03:00
script feat: initial commit 2022-07-17 21:57:09 +03:00
src feat: initial commit 2022-07-17 21:57:09 +03:00
test test: rename test contract to "FooTest" 2022-11-18 21:50:45 +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 chore: change testnet to Sepolia 2022-10-30 18:28:21 +02:00
.gitignore feat: initial commit 2022-07-17 21:57:09 +03:00
.gitmodules build: bump "forge-std" to v1.0.0 2022-11-01 10:34:03 +02:00
.lintstagedrc.yml chore: fix lint-staged config 2022-10-16 12:44:50 +03:00
.prettierignore feat: initial commit 2022-07-17 21:57:09 +03:00
.prettierrc.yml style: enable "useTabs" Prettier rule 2022-10-31 18:33:56 +02:00
.solhint.json feat: initial commit 2022-07-17 21:57:09 +03:00
.solhintignore feat: initial commit 2022-07-17 21:57:09 +03:00
.yarnrc.yml build: upgrade to yarn v3.2.4 2022-10-30 18:39:19 +02:00
LICENSE.md style: run Prettier over Markdown files 2022-10-16 12:55:21 +03:00
README.md style: run Prettier over Markdown files 2022-10-16 12:55:21 +03:00
foundry.toml chore: update "fuzz" object in Foundry config 2022-10-29 13:41:24 +03:00
package.json build: add resolution for "@solidity-parser/parser" 2022-10-30 18:46:48 +02:00
remappings.txt chore: add "src" to remappings 2022-11-20 16:34:27 +02:00
yarn.lock build: add resolution for "@solidity-parser/parser" 2022-10-30 18:46:48 +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, debug and deploy smart contracts
  • PRBTest: modern collection of testing assertions and logging utilities
  • Forge Std: collection of helpful contracts and cheatcodes for testing
  • Solhint: code linter
  • Prettier Plugin Solidity: code formatter

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 and prettier and other goodies

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 documentations.

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
├── .prettierignore
├── .prettierrc.yml
├── .solhintignore
├── .solhint.json
├── .yarnrc.yml
├── foundry.toml
└── remappings.txt

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 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 -vvvv 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

Deploy

Deploy to Anvil:

$ forge script script/Foo.s.sol:FooScript --fork-url http://localhost:8545 \
 --broadcast --private-key $PRIVATE_KEY

For instructions on how to deploy to a testnet or mainnet, check out the Solidity Scripting tutorial.

Format

Format the contracts with Prettier:

$ yarn prettier

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