foundry
Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
Foundry consists of:
- Forge: Ethereum testing framework (like Truffle, Hardhat and Dapptools).
- Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
Forge
cargo install --git https://github.com/gakonst/foundry --bin forge --locked
If you are on a x86/x86_64 Unix machine, you can also use --features=solc-asm
to enable Sha2 Assembly instructions, which further speedup the compilation pipeline cache.
We also recommend using forgeup for managing various versions of Forge, so that you can easily test out bleeding edge changes in open pull requests or forks from contributors.
More documentation can be found in the forge package and in the CLI README.
Features
- Fast & flexible compilation pipeline:
- Automatic Solidity compiler version detection & installation (under
~/.svm
) - Incremental compilation & caching: Only changed files are re-compiled
- Parallel compilation
- Non-standard directory structures support (e.g. can build Hardhat repos)
- Automatic Solidity compiler version detection & installation (under
- Tests are written in Solidity (like in DappTools)
- Fast fuzz Tests with shrinking of inputs & printing of counter-examples
- Fast remote RPC forking mode leveraging Rust's async infrastructure like tokio
- Flexible debug logging:
- Dapptools-style, using
DsTest
's emitted logs - Hardhat-style, using the popular
console.sol
contract
- Dapptools-style, using
- Portable (5-10MB) & easy to install statically linked binary without requiring Nix or any other package manager
- Abstracted over EVM implementations (currently supported: Sputnik, EvmOdin)
How Fast?
Forge is quite fast at both compiling (leveraging the ethers-solc package) and testing.
Some benchmarks below:
Project | Forge | DappTools | Speedup |
---|---|---|---|
guni-lev | 28.6s | 2m36s | 5.45x |
solmate | 6s | 46s | 7.66x |
geb | 11s | 40s | 3.63x |
vaults | 1.4s | 5.5s | 3.9x |
It also works with "non-standard" directory structures (i.e. contracts not in src/
, libraries not in lib/
). When tested with openzeppelin-contracts
, Hardhat compilation took 15.244s, whereas Forge took 9.449 (~4s cached)
Cast
Cast is a swiss army knife for interacting with Ethereum applications from the command line.
cargo install --git https://github.com/gakonst/foundry --bin cast
// Get USDC's total supply
cast call 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 "totalSupply()(uint256)" --rpc-url <..your node url>
More documentation can be found in the cast package.
Contributing
Directory structure
This repository contains several Rust crates:
forge
: Library for building and testing a Solidity repository.cast
: Library for interacting with a live Ethereum JSON-RPC compatible node, or for parsing data.cli
: Command line interfaces tocast
andforge
.evm-adapters
: Unified layer of abstraction over multiple EVM types. Currently supported EVMs: Sputnik, Evmodin.utils
: Utilities for parsing ABI data, will eventually be upstreamed to ethers-rs.
Rust Toolchain
We use the stable Rust toolchain. Install by running: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
.
Minimum Supported Rust Version
The current minimum supported Rust version is rustc 1.54.0 (a178d0322 2021-07-26)
.
Testing
cargo check
cargo test
cargo doc --open
Formatting
We use the nightly toolchain for formatting and linting.
cargo +nightly fmt
cargo +nightly clippy --all-features -- -D warnings
Getting Help
First, see if the answer to your question can be found in the API documentation. If the answer is not there, try opening an issue with the question.
Join the foundry telegram to chat with the community!
Acknowledgements
- Foundry is a clean-room rewrite of the testing framework dapptools. None of this would have been possible without the DappHub team's work over the years.
- Matthias Seitz: Created ethers-solc which is the backbone of our compilation pipeline, as well as countless contributions to ethers, in particular the
abigen
macros. - Rohit Narurkar: Created the Rust Solidity version manager svm-rs which we use to auto-detect and manage multiple Solidity versions.
- Brock Elmore: For extending the VM's cheatcodes and implementing structured call tracing, a critical feature for debugging smart contract calls.
- All the other contributors to the ethers-rs & foundry repositories and chatrooms.