• Stars
    star
    560
  • Rank 79,541 (Top 2 %)
  • Language
    Solidity
  • License
    MIT License
  • Created over 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Foundry-based template for developing Solidity smart contracts

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
  • Forge Std: collection of helpful contracts and cheatcodes for testing
  • PRBTest: modern collection of testing assertions and logging utilities
  • Prettier: code formatter for non-Solidity files
  • Solhint Community: linter for Solidity code

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:

$ mkdir my-project
$ cd my-project
$ forge init --template PaulRBerg/foundry-template
$ 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/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

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.

Related Efforts

License

This project is licensed under MIT.

More Repositories

1

hardhat-template

Hardhat-based template for developing Solidity smart contracts
TypeScript
1,958
star
2

prb-math

Solidity library for advanced fixed-point math
Solidity
876
star
3

prb-proxy

Proxy contract to compose Ethereum transactions
Solidity
271
star
4

prb-test

Modern collection of testing assertions and logging utilities for Solidity
Solidity
181
star
5

prb-contracts

Off-the-shelf Solidity smart contracts
Solidity
132
star
6

multisol

CLI application for verifying Solidity contracts on Etherscan
Rust
113
star
7

rust-template

A template for developing Rust projects, with sensible defaults
Rust
84
star
8

awesome-zkp-starter-pack

A curated collection of links for zero-knowledge proof cryptography used in blockchains
70
star
9

btt-examples

Examples for Branching Tree Technique, a simple specification framework for writing structured Solidity tests
Solidity
58
star
10

evm-bn

Convert fixed-point numbers to ethers big numbers and vice-versa.
TypeScript
49
star
11

check-same-sign

Gas golfing the most gas efficient way to check if two integers have the same sign in Solidity
Solidity
46
star
12

foundry-multibuild

GitHub Action for building a Foundry project with a range of Solidity versions
Shell
39
star
13

hardhat-packager

Hardhat plugin for preparing the contract artifacts and the TypeChain bindings for registry deployment
TypeScript
35
star
14

ethsum

Simple Ethereum address checksum tool
JavaScript
33
star
15

solplate

Simple utility for generating boilerplate Solidity contracts
Rust
32
star
16

typescript-template

A template for developing TypeScript project, with sensible defaults
TypeScript
32
star
17

awesome-many-worlds

Curated collection of educational materials on the many-worlds interpretation of quantum mechanics
25
star
18

github-labels

GitHub labels to use across repositories
Shell
21
star
19

CoinMarketCap-Desktop

A simple desktop wrapper for CoinMarketCap
JavaScript
21
star
20

cryptfolio-scripts

A collection of Google Apps Script custom functions for tracking crypto portfolios in Google Sheets
JavaScript
20
star
21

erc2212

Reference implementation for ERC-2212
JavaScript
12
star
22

unchecked-counter

Solidity counter type that bypasses checked arithmetic
Solidity
12
star
23

create2-repro

Repo to reproduce the inconsistent CREATE2 behavior in Foundry
Solidity
11
star
24

contractz

Sketchbook for my Ethereum contracts
Solidity
11
star
25

modlizer

Struggling with iOS design patterns? Embrace Modlizer
Swift
11
star
26

defi-types

TypeChain bindings for DeFi protocols
Solidity
10
star
27

dyi-crypto-taxes

Spreadsheet templates and practical tips and tricks for doing your taxes alone
10
star
28

abdk-gas-estimations

Gas estimations for ADBKMath64x64
Solidity
9
star
29

rust-book-annotations

My absorption of the Rust Book
Rust
8
star
30

javascript-template

A template for developing JavaScript projects, with sensible defaults
JavaScript
7
star
31

typescript-monorepo-template

Dummy monorepo set up with Typescript and Yarn Workspaces
TypeScript
4
star
32

tft

Browser extension that prevents typos by asking you to double-check the content before posting a long tweet
JavaScript
3
star
33

foundry-expect-emit-bug

Repo to reproduce the bug I ran into while writing tests with Foundry
Solidity
3
star
34

cea-contracts

Base smart contracts used in the default template of Create Eth App
JavaScript
3
star
35

my-eth-app

Default boilerplate code generated by create-eth-app
HTML
3
star
36

hardhat-prb

Hardhat plugins to complement the PRB smart contract libraries
TypeScript
3
star
37

react-hooks

React Hooks to be shared across my personal projects and packages
JavaScript
2
star
38

flipper-ui

The frontend app for the users of Flipper.
JavaScript
2
star
39

web3-react-blobs

Blobs of web3-react code used in the Sablier Interface
JavaScript
2
star
40

forge-coverage-bug

Repo to reproduce the bug in the forge coverage command
Solidity
2
star
41

PaulRBerg.github.io

My personal website
HTML
2
star
42

xstate-useActor-bug

xstate useActor bug
TypeScript
2
star
43

vscode-dictionary

Personal dictionary for vscode-spell-checker
2
star
44

prb-proxy-frontend

Landing page for PRBProxy
TypeScript
2
star
45

eslint-config

Eslint config to be shared across my personal projects and packages
JavaScript
2
star
46

test-foundry-template

Solidity
2
star
47

rage-stream

Rage stream functionality added to Sablier
TypeScript
1
star
48

airdropx

Firebase backend for the AirdropX Telegram bot
JavaScript
1
star
49

learn-plasma-rss

RSS feed for Plasma resources
JavaScript
1
star
50

paulrberg-labelsync

Dummy repo for label-sync.com
1
star
51

sketchpad

Personal repo for learning, logs and constants
JavaScript
1
star
52

cea-template

The official base template for Create Eth App.
HTML
1
star
53

hardhat-ignition-basic

Dummy project for going through the [email protected] basic tutorial
TypeScript
1
star
54

buidler-invalid-opcode

Reproduces the ganache-cli invalid opcode bug
TypeScript
1
star
55

yarn-rc34-error

Dummy project to reproduce the errors I encountered with [email protected]
JavaScript
1
star
56

ethiasi

Landing page for the first Ethereum event in Iasi, Romania
CSS
1
star
57

ethereum-signatures-progress

A collection of links and resources I collected in order to implement EIP-191 and EIP-712 into geth.
1
star
58

codebase-go

Personal repo for learning, logs and constants related to golang.
Go
1
star
59

dfe

Browser extension that hides the price of Ether
JavaScript
1
star