A Foundry-based template for Solidity smart contract development.
- Forge: compile, test, fuzz, format, and deploy smart contracts
- Forge Std: collection of helpful contracts and utilities for testing
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 lambdalf-dev/web3-template
$ yarn installIf 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:
├── .gitignore
├── foundry.toml
└── remappings.txt
This template comes with a set of preconfigured tasks. You can find them in package.json.
This template is developped in a container so you don't need to have any tools on your computer besides your text editor. Just open the project in the container and you're ready to go.
If you prefer not to use the container, you can install the dependencies as follow:
- Install Foundry with
curl -L https://foundry.paradigm.xyz | bash
foundryup- Install the dependencies with
forge soldeer install
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 -vvvv flag and use console.log.
This template comes with a TestHelper.sol that you can import in your test with useful constants and predefined users.
This template comes with a prebuilt NFT contract featuring:
- a whitelisted free claim
- a whitelisted private sale with its own price
- a public sale with its own price and a general transaction limit
- a reserve for airdrop by the team
Build the contracts:
yarn buildforge buildforge compile
Delete the build artifacts and cache directories:
yarn cleanforge clean
Get a test coverage report:
yarn coverageforge coverage
Get a gas report:
yarn gasforge test --gas-report
Format the contracts:
yarn lintforge fmt check
Run all tests:
yarn testforge test
Run all tests with verbose output:
yarn test:verboseforge test -vvvv
Run all unit tests (test name starts with "test_unit_"):
yarn test:unitforge test --mt test_unit_
Run all fuzz tests (test name starts with "test_fuzz_"):
yarn test:fuzzforge test --mt test_fuzz_
Run all edge tests (test name starts with "test_edge_"):
yarn test:edgeforge test --mt test_edge_