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.
curl https://raw.githubusercontent.com/gakonst/foundry/master/foundryup/install | bash
in a new terminal session or after reloading your PATH:
foundryup
Just get foundryup, the Foundry toolchain installer, and use it to install the latest forge and cast binaries.
Advanced ways to use foundryup and other documentation can be found in the foundryup package. Happy forging!
More documentation can be found in the forge package and in the CLI README.
- 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.solcontract
- 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)
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 is a swiss army knife for interacting with Ethereum applications from the command line.
More documentation can be found in the cast package.
juanfranblanco/vscode-solidity describes in detail how to configure
the vscode extension.
If you're using dependency libraries, then you'll need _ Remappings_ so the extension can find the imports.
The easiest way to add remappings is creating a remappings.txt file in the root folder, which can be generated with
auto inferred remappings:
forge remappings > remappings.txtSee also ./cli/README.md.
Alternatively you can use the extension's dir structure settings to configure your contracts and dependency directory.
If your contracts are stored in ./src and libraries in ./lib, you can add
"solidity.packageDefaultDependenciesContractsDirectory": "src",
"solidity.packageDefaultDependenciesDirectory": "lib"to your .vscode file
It's also recommended to specify a solc compiler version for the extension, read more:
"solidity.compileUsingRemoteVersion": "v0.8.10"You can generate autocompletion shell scripts for bash, elvish, fish, powershell, and zsh.
Example (zsh / oh-my-zsh)
mkdir -p ~/.oh-my-zsh/completions
forge completions zsh > ~/.oh-my-zsh/completions/_forge
cast completions zsh > ~/.oh-my-zsh/completions/_cast
source ~/.zshrcThis 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 tocastandforge.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.
We use the stable Rust toolchain. Install by running:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh.
The current minimum supported Rust version is
rustc 1.54.0 (a178d0322 2021-07-26).
cargo check
cargo test
cargo doc --openWe use the nightly toolchain for formatting and linting.
cargo +nightly fmt
cargo +nightly clippy --all-features -- -D warnings
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!
- 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
abigenmacros. - 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.