Foundry-based template for developing Solidity smart contracts. Dependencies are managed as Node.js packages (via Bun)
and remapped through remappings.txt instead of git submodules.
- Solidity
0.8.29(pragma>=0.8.29), EVM targetshanghai, optimizer on (10,000 runs) - Foundry (
forge) — compile, test, fuzz, format, deploy - Forge Std
v1.9.7— test and scripting framework - OpenZeppelin Contracts
5.3.0— pre-installed contract library - Bun — dependency manager (deps installed as Node.js packages, remapped in
remappings.txt) - Prettier
3.5— formatter for JSON/Markdown/YAML - Solhint
5.1— Solidity linter
forge build— compile contractsforge build --sizes— compile and print contract sizes (CI build step)forge test— run the test suiteforge test -vvv— run tests withconsole2logs shownforge test --gas-report— run tests with a gas reportforge coverage— generate a coverage reportforge fmt— format Solidityforge fmt --check— check Solidity formatting without writingforge clean— deleteout/andcache/forge config— print the resolved Foundry configforge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545— deployFooto a local node (requiresMNEMONICorETH_FROM)forge script script/DeployBrowser.s.sol --broadcast --fork-url http://localhost:8545 --browser— deployFooto a local node (requires you to connect your wallet at localhost:9545)
bun install— install Node.js dependencies (add a matching entry toremappings.txtafterward)bun run build—forge buildbun run test—forge testbun run clean—rm -rf cache outbun run forge-check—forge fmt --checkbun run forge-write—forge fmtbun run solhint-check— Solhint over{script,src,tests}/**/*.solbun run prettier:check— Prettier check over**/*.{json,md,yml}bun run prettier:write— Prettier write over**/*.{json,md,yml}bun run full-check—forge-check+solhint-check+prettier:check(the CI lint gate)bun run full-write—forge-write+prettier:write(auto-fix formatting)
src/— contracts under development (Foo.solis the example)tests/— Foundry tests (configured viatest = "tests"infoundry.toml)script/— deployment scripts;Base.s.soldefinesBaseScript(broadcaster setup +broadcastmodifier)out/,cache/— build artifacts and forge cache (gitignored)node_modules/— dependencies, mapped to import paths inremappings.txt- Config:
foundry.toml,remappings.txt,.solhint.json,.prettierrc.yml,.editorconfig,.env.example
- Solidity — formatted by
forge fmt([fmt]infoundry.toml): 120-char lines, 4-space indent, double quotes, bracket spacing, long int types (uint256, notuint), thousands underscores, multiline function headers, wrapped comments. - Solhint (
.solhint.json) — extendssolhint:recommended; compiler>=0.8.29; max line length 120; explicit function visibility (constructors exempt);one-contract-per-file,not-rely-on-time, andno-consoledisabled. - Non-Solidity — Prettier (
.prettierrc.yml):printWidth120,trailingComma: all, MarkdownproseWrap: always. - EditorConfig — LF endings, UTF-8, final newline, trim trailing whitespace; 2-space default, 4-space for
.sol, 1-space for.tree. - Every file carries an SPDX header; pragma is
>=0.8.29for contracts and>=0.8.29 <0.9.0for tests and scripts.
- Test naming:
test_*(unit),testFuzz_*(fuzz),testFork_*(fork). Test contracts inheritforge-std'sTest;setUp()runs before each case. - Fuzz runs: 1,000 under the
defaultprofile, 10,000 underci. - Fork tests: read
API_KEY_ALCHEMYand silently pass when it is unset. - Scripts: inherit
BaseScript; the broadcaster is taken from$ETH_FROM, else derived from$MNEMONIC(falls back to a test mnemonic so scripts compile without env vars). - Adding dependencies:
bun install <pkg>(orbun install github:user/repo), then addname=node_modules/nametoremappings.txt. Do not use git submodules. - Env vars (see
.env.example):API_KEY_ALCHEMY,API_KEY_ETHERSCAN,API_KEY_INFURA,MNEMONIC,FOUNDRY_PROFILE;ETH_FROMoptionally overrides the broadcaster. - Profiles:
defaultandci(10k fuzz runs, verbosity 4), selected viaFOUNDRY_PROFILE. - RPC + Etherscan: endpoints for mainnet, sepolia, arbitrum, avalanche, base, bnb_smart_chain, gnosis_chain,
optimism, polygon, and localhost are defined in
foundry.toml.
- Default branch:
main. - CI (
.github/workflows/ci.yml) runs on every push/PR tomainunder theciprofile: lint (bun run full-check) → build (forge build --sizes) → test (forge test). - Before opening a PR, run
bun run full-check(orbun run full-writeto auto-fix) andforge test.