Foundry

Definition:

Foundry is a modular, Rust-powered Ethereum development framework consisting of Forge (smart contract testing and deployment), Cast (EVM RPC command-line interface), Anvil (local EVM node), and Chisel (Solidity REPL) — distinguished from Hardhat and Truffle by its near-instant compilation speeds, native Solidity testing (no JavaScript required), and deep fuzzing capabilities that make it the preferred development environment for security-focused and performance-intensive smart contract work. Foundry was built by Paradigm and is open-source under MIT license.


Components

Forge — Testing and Compilation:

Forge is the central tool for writing, compiling, and testing Solidity contracts:

  • Tests are written in Solidity (not JavaScript/TypeScript like Hardhat)
  • Extremely fast compilation via Foundry’s Rust-based Solidity compiler wrapper
  • Built-in fuzzing: property-based tests with automatic input generation
  • Symbolic execution support (via Halmos integration)
  • Fork testing: tests run against a live mainnet fork at a specific block

Cast — EVM RPC CLI:

Cast is a Swiss-army knife CLI for interacting with any EVM node:

“`bash

cast call 0xContractAddress “balanceOf(address)(uint256)” 0xWallet

cast send 0xContractAddress “transfer(address,uint256)” 0xRecipient 1000000

cast block latest # inspect block data

cast decode-input “transfer(address,uint256)” 0xcalldata

“`

Anvil — Local EVM Node:

Anvil is a fast local Ethereum node for development:

  • Replaces Ganache and Hardhat Network
  • Supports mainnet forking (run tests against mainnet state)
  • Byzantine/London/Shanghai/Cancun fork support
  • State serialization and resumption

Chisel — Solidity REPL:

Interactive Solidity shell:

“`bash

$ chisel

» uint256 x = 5;

» x * x

Type: uint256

Value: 25

“`


Testing in Solidity

Foundry’s flagship feature: tests are Solidity contracts inheriting from Test:

“`solidity

import “forge-std/Test.sol”;

contract MyContractTest is Test {

MyContract target;

function setUp() public {

target = new MyContract();

}

function testBasic() public {

assertEq(target.getValue(), 42);

}

// Fuzz test: Forge automatically generates 256 random inputs

function testFuzz_AddAlwaysPositive(uint256 a, uint256 b) public {

vm.assume(a < type(uint128).max && b < type(uint128).max);

uint256 result = target.add(a, b);

assertTrue(result >= a);

}

}

“`

Cheatcodes (vm):

Foundry provides powerful test cheatcodes via the vm object:

  • vm.prank(address) — next call impersonates address
  • vm.deal(address, amount) — set ETH balance
  • vm.warp(timestamp) — set block.timestamp
  • vm.expectRevert(bytes) — assert a revert happens
  • vm.expectEmit(...) — assert specific event emission

Foundry vs. Hardhat

Feature Foundry Hardhat
Test language Solidity JavaScript/TypeScript
Compilation speed Very fast (Rust) Slower (JS)
Fuzzing Native, robust Plugin required
TypeScript support Less native First-class
Existing ecosystem Growing Larger plugin library
Gas snapshots Built-in Via plugins
Adoption trend Growing fast (2022–2024) Dominant pre-2022

Many teams now use both: Foundry for unit/fuzz tests, Hardhat for integration and deployment pipelines.


Installation

“`bash

curl -L https://foundry.paradigm.xyz | bash

foundryup

forge –version

“`


Adoption

Foundry is used by:

  • Uniswap v4 — primary test suite
  • Aave v3 — partial migration to Foundry
  • Most new DeFi protocol launches post-2022
  • Web3 security audit firms — as the standard environment

Related Terms


Sources

Last updated: 2026-04