Foundry ERC-20 — Learning Notes
A learning project for writing an ERC-20 token with Foundry. This repo is my own notes-on-the-way — expect experiments, scaffolding, and takeaways, not a finished production token.
Status: early scaffold. The
Counterexample has been kept as-is while I set up the project structure and Foundry toolchain; the ERC-20 implementation is next.
Why this exists
I'm moving from traditional web development into Web3 / smart contract development. Foundry is the toolchain I chose to learn Solidity testing and deployment properly. This repo is where I keep the lessons as I go, so I can revisit them and so each commit shows what I actually learned (not what I'd like people to think I know).
What Foundry gives you
Foundry is a fast, portable, modular EVM development toolkit written in Rust:
- Forge — the testing framework (like Truffle / Hardhat / DappTools).
- Cast — a Swiss-army knife for talking to contracts, sending transactions, reading chain data.
- Anvil — a local Ethereum node for testing (like Ganache / Hardhat Network).
- Chisel — a fast Solidity REPL for trying snippets quickly.
Project layout
├── lib/ # dependencies (forge-std, openzeppelin-contracts)
├── script/ # deployment scripts
├── src/ # contracts
├── test/ # tests
└── foundry.toml
Dependencies are pulled in as git submodules. OpenZeppelin is included because its
ERC20 base is what most real tokens build on — rather than reimplementing the
standard from scratch (and getting the edge cases wrong).
Learning plan
- Scaffold — get Foundry building / testing the default
Counterexample. ✅ - Dependencies — wire up forge-std + OpenZeppelin as submodules. ✅
- ERC-20 token — inherit OpenZeppelin's
ERC20, learn the constructor, minting, decimals. - Tests — unit tests + fuzz tests for the token (balance, transfer, allowance).
- Deploy script — a repeatable deploy against a local Anvil chain.
Usage
# build
forge build
# test
forge test
# format
forge fmt
# gas snapshots
forge snapshot
# local node
anvil
# deploy (example — replace with your RPC URL / key)
forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
# interact with the chain
cast <subcommand>
Documentation
- Foundry book: https://book.getfoundry.sh/
- OpenZeppelin ERC-20: https://docs.openzeppelin.com/contracts/4.x/erc20