Introduction
Foundry is an Ethereum development toolkit built in Rust by Paradigm. It replaces JavaScript-based workflows with native-speed tooling for compiling, testing, deploying, and interacting with smart contracts. Foundry has become the preferred toolkit for teams that write tests in Solidity rather than JavaScript.
What Foundry Does
- Compiles Solidity and Vyper contracts with parallel compilation via
forge build - Runs Solidity-native unit and fuzz tests at native speed with
forge test - Provides
castCLI for sending transactions, querying chain state, and decoding calldata - Spins up a local Ethereum node with
anvilfor development and forked mainnet testing - Offers
chisel, an interactive Solidity REPL for quick experimentation
Architecture Overview
Foundry is a set of Rust binaries sharing a common library layer. Forge handles project management, compilation (via solc), and test execution using a built-in EVM (revm). Anvil implements a full JSON-RPC server backed by revm, supporting mainnet forking at any block. Cast wraps common RPC calls and ABI encoding into one-line CLI commands. The toolkit uses the Alloy library for Ethereum type handling and RPC transport.
Self-Hosting & Configuration
- Install via
foundryupor build from source withcargo build --release - Configure project settings in
foundry.toml(Solidity version, optimizer runs, RPC URLs) - Use
forge installto manage Solidity dependencies as Git submodules - Set
ETH_RPC_URLenvironment variable for default chain interaction - Fork mainnet with
anvil --fork-url <RPC_URL>for realistic integration tests
Key Features
- Fuzz testing with configurable runs and shrinking for finding edge cases
- Mainnet forking in Anvil lets you test against live contract state
- Gas snapshots (
forge snapshot) track contract gas usage across commits - Cheatcodes in tests allow time manipulation, storage overrides, and impersonation
- Script system (
forge script) deploys contracts with simulation before broadcast
Comparison with Similar Tools
- Hardhat — JavaScript-based with a rich plugin ecosystem; Foundry is faster and uses Solidity for tests
- Brownie — Python-based framework now largely unmaintained; Foundry is actively developed
- Truffle — Early Ethereum framework; Foundry offers modern DX and superior test speed
- Ape — Python framework by ApeWorX; Foundry appeals to developers preferring Solidity-native testing
FAQ
Q: Can I use Foundry alongside Hardhat? A: Yes. Many teams use Forge for testing and Hardhat for deployment scripts or plugins. The two can coexist in the same repository.
Q: Does Foundry support Vyper? A: Foundry supports compiling Vyper contracts, though the primary testing workflow targets Solidity.
Q: How does fuzz testing work in Forge? A: Forge generates random inputs for test function parameters and runs them many times (default 256 runs). Failing inputs are automatically minimized to the simplest reproducing case.
Q: Is Foundry production-ready? A: Yes. Major protocols including Uniswap, Optimism, and Paradigm use Foundry in production.