Foundry Setup Template
A template repository for Foundry/Solidity projects with CI, static analysis, and auto-generated docs.
Quick Start
Prerequisites: Install Foundry
# Clone and set up
git clone https://github.com/owieth/foundry-setup
cd foundry-setup
forge install
# Copy environment variables
cp .env.example .env
# Fill in your values, then:
source .env
Local Development
Build & Test
forge build
forge test -vvvv
forge snapshot
Format
forge fmt
forge fmt --check
Generate Docs
forge doc
forge doc --serve # preview at http://localhost:3000
Deploy
source .env
forge script script/<Script>.s.sol:<Contract> --rpc-url <chain> --broadcast --verify -vvvvv
Local Fork with Anvil
# Fresh local chain
anvil
# Fork Sepolia
anvil -f https://eth-sepolia.g.alchemy.com/v2/<your_api_key>
Contract Layout
Layout of **.sol:
- version
- imports
- interfaces, libraries, contracts
- usings (
using ... for ...) - errors
- type declarations
- state variables
- events
- modifiers
- functions
Layout of functions (inside **.sol after modifiers):
- constructor
- receive (if exists)
- fallback (if exists)
- external
- public
- internal
- private
- view & pure (last per visibility group)
More → STYLE.md
Token
Inherits: ERC20, Ownable
Title: Token Test Contract
Author: Olivier Winkler (https://github.com/owieth)
Note: security-contact: xxx@gmail.com
State Variables
CONSTANT_NUMBER
Explain to a developer any extra details
uint256 private constant CONSTANT_NUMBER = 100
i_immutableNumber
Explain to a developer any extra details
uint256 private immutable i_immutableNumber = 100
s_number
Explain to a developer any extra details
uint256 private s_number
Functions
onlyMinter
Explain to a developer any extra details
modifier onlyMinter() ;
onlyMinterByAddress
Explain to a developer any extra details
modifier onlyMinterByAddress(address minter) ;
Parameters
| Name | Type | Description |
|---|---|---|
minter | address | a parameter just like in doxygen (must be followed by parameter name) |
constructor
constructor(address initialOwner) ERC20("Token", "TKN") Ownable(initialOwner);
setNumber
Explain to an end user what this does
Explain to a developer any extra details
function setNumber(uint256 newNumber) external;
Parameters
| Name | Type | Description |
|---|---|---|
newNumber | uint256 | a parameter just like in doxygen (must be followed by parameter name) |
incrementNumber
Explain to an end user what this does
Explain to a developer any extra details
function incrementNumber() public;
getCurrentNumber
Explain to an end user what this does
Explain to a developer any extra details
function getCurrentNumber() public view returns (uint256);
_calculateNumber
Explain to an end user what this does
Explain to a developer any extra details
function _calculateNumber() internal;
_calculateAmount
Explain to an end user what this does
Explain to a developer any extra details
function _calculateAmount() private;
Events
TokenEvent
Explain to a developer any extra details
event TokenEvent(address indexed from, address indexed to, address indexed id);
Parameters
| Name | Type | Description |
|---|---|---|
from | address | a parameter just like in doxygen (must be followed by parameter name) |
to | address | a parameter just like in doxygen (must be followed by parameter name) |
id | address | a parameter just like in doxygen (must be followed by parameter name) |
Errors
Token__Error
Explain to a developer any extra details
error Token__Error();
Token__ErrorWithParams
Explain to a developer any extra details
error Token__ErrorWithParams(uint256 id);
Parameters
| Name | Type | Description |
|---|---|---|
id | uint256 | a parameter just like in doxygen (must be followed by parameter name) |
Structs
TokenStruct
Explain to a developer any extra details
struct TokenStruct {
uint256 id;
string name;
}
Properties
| Name | Type | Description |
|---|---|---|
id | uint256 | a parameter just like in doxygen (must be followed by parameter name) |
name | string | a parameter just like in doxygen (must be followed by parameter name) |