Foundry-based template for developing Solidity smart contracts used by Vac
Go to file
Paul Razvan Berg bf567974af
Merge pull request #19 from 0xcacti/patch-1
2023-04-17 08:58:42 +03:00
.github ci: use specific pnpm version 2023-03-28 19:08:53 +03:00
.vscode chore: mark "lib" as vendored code 2023-04-07 22:08:31 +03:00
lib build: bump "prb-math" 2023-03-19 17:46:01 +02:00
script build: upgrade to Solidity v0.8.19 2023-02-25 12:40:42 +02:00
src build: bump "prb-test" 2023-03-04 12:37:52 +02:00
test test: mark setUp as virtual 2023-04-01 09:46:18 +03:00
.editorconfig chore: fix indenting for *.sol in .editorconfig 2022-09-15 00:57:35 +02:00
.env.example chore: update examples in ".env.example" 2023-03-04 00:25:36 +02:00
.gitattributes chore: mark "lib" as vendored code 2023-04-07 22:08:31 +03:00
.gitignore chore: simplify globs in ignore files 2023-03-13 15:31:43 +02:00
.gitmodules build: pin "prb-math" submodule to "v3" branch 2023-02-08 22:42:48 +02:00
.prettierignore chore: simplify globs in ignore files 2023-03-13 15:31:43 +02:00
.prettierrc.yml chore: remove Prettier overrides for "*.sol" 2023-03-13 17:58:43 +02:00
.solhint.json build: upgrade to Solidity v0.8.19 2023-02-25 12:40:42 +02:00
LICENSE.md chore: update copyright year in license 2023-01-01 13:26:12 +02:00
README.md docs: update wording in README 2023-03-16 18:50:47 +02:00
foundry.toml Update foundry.toml 2023-04-16 23:06:26 -04:00
package.json build: remove "rimraf" Node.js dep 2023-04-11 22:23:15 +03:00
pnpm-lock.yaml build: remove "rimraf" Node.js dep 2023-04-11 22:23:15 +03:00
remappings.txt chore: add "src" to remappings 2022-11-20 16:34:27 +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
pnpm install # install Solhint, Prettier, and other Node.js deps

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

Sensible Defaults

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

VSCode Integration

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.

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.

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

Usage

This is 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:

$ pnpm lint

Test

Run the tests:

$ forge test

Notes

  1. Foundry uses git submodules to manage dependencies. For detailed instructions on working with dependencies, please refer to the guide 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 fork.

License

This project is licensed under MIT.