Skip to content

minwoogramer/foundry-template

Repository files navigation

Foundry Template Contract

This project was tested by using foundry. foundry is contract tool for deploy, test by solidity.

foundry use git submodule , submodules don't scale.

  1. Slow installation times
  2. Switching between branches produces git diffs when the submodules are different
  3. Need custom helpers like this "reinit"

So this template uses Node.js packages by yarn.

What's Project Inside

  • Forge: compile, test, fuzz, format, and deploy smart contracts
  • Forge Std: collection of helpful contracts and cheatcodes for testing
  • DSTest: Forge Std collection of testing assertions and logging utilities
  • PRBTest: modern collection of testing assertions and logging utilities
  • Solhint: linter for Solidity code
  • OpenzeppelinV4.9.5 : Contract code for develop more easier

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:

├── .gitignore
├── .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.

Installing Dependencies

Foundry typically uses git submodules to manage dependencies, but this template uses Node.js packages because

This is how to install dependencies:

  1. Install the dependency using your preferred package manager, e.g. bun install dependency-name
    • Use this syntax to install from GitHub: bun install github:username/repo-name
  2. Add a remapping for the dependency in remappings.txt, e.g. dependency-name=node_modules/dependency-name

Note that OpenZeppelin Contracts is pre-installed, so you can follow that as an example.

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:

$ bun run lint

Test

Run the tests:

$ forge test

More Detail(console) test:

forge test -vv

More Detail(console and onChain Event):

forge test -vvv

If you want to test contract in env of mainnet:

$ bun run test:fork:mainnet

Generate test coverage and output result to the terminal:

$ bun run test:coverage

Generate test coverage with lcov report (you'll have to open the ./coverage/index.html file in your browser, to do so simply copy paste the path):

$ bun run test:coverage:report

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors