Foundry: Forge, Cast, Anvil
The modern Solidity workflow. forge for compiling and testing in Solidity itself, cast for CLI interaction with any chain, anvil for local mainnet forks. Why this stack replaced Hardhat.
40 min · expert · part of Solidity & Smart Contract Development
What you'll learn
- Why Foundry, and Why It Replaced Hardhat
- forge init: Project Layout and foundry.toml
- Writing Tests in Solidity
- Fuzz Tests and Invariant Tests
- Cast: The CLI for Any EVM Chain
- Anvil: Local Mainnet Forks
- forge script: Deploy and Migration
Key terms
- forge
- Foundry's compiler, test runner, and project manager. The command you'll use most: `forge build`, `forge test`, `forge script`.
- cast
- Foundry's CLI for interacting with any EVM chain. Read state, send transactions, decode calldata, trace failed transactions. Replaces ad-hoc ethers.js scripts.
- anvil
- Foundry's local Ethereum node. Forks mainnet state at any block so you can run real-protocol integration tests locally with no fees.
- Cheatcode (vm.*)
- Special functions exposed by Foundry's test environment to manipulate state in ways the EVM normally forbids: change msg.sender, warp time, give addresses arbitrary balances, expect reverts, etc.
- Fuzz Test
- A test function that takes parameters; Foundry runs it many times with random inputs and shrinks any failing input to the minimal counterexample.
- Invariant Test
- A test where you specify properties that must always hold, plus a "handler" contract Foundry calls at random. The runner explores call sequences to find any that break the invariants.
- forge install (git submodule)
- Foundry's dependency mechanism. Dependencies are pinned to specific commits via git submodules, not npm versions — fully reproducible, no transitive ambiguity.
Read the full lesson in the CryptoBipto app.
Open lessonEducational only — not financial advice.
