Skip to content

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

flanagansteve/foundry

 
 

Repository files navigation

Foundry

Github Actions Telegram Chat Telegram Support Crates.io

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.

Need help getting started with Foundry? Read the 📖 Foundry Book (WIP)!

demo

Installation

First run the command below to get foundryup, the Foundry toolchain installer:

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

If you do not want to use the redirect, feel free to manually download the foundryup installation script from here.

Then, in a new terminal session or after reloading your PATH, run it to get the latest forge and cast binaries:

foundryup

Advanced ways to use foundryup, and other documentation, can be found in the foundryup package. Happy forging!

Installing from source

For people that want to install from source, you can do so like below:

git clone https://github.com/gakonst/foundry
cd foundry
cargo build --release
# copy the binaries under `./target/release/{forge, cast}` to your $PATH.

Or via cargo install --git https://github.com/gakonst/foundry --locked

Installing via Docker

Foundry maintains a Docker image repository.

You can pull the latest release image like so:

docker pull ghcr.io/gakonst/foundry:latest

For examples and guides on using this image, see the Docker section in the book.

Releases

You can manually download nightly releases here.

Forge

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. Hardhat repos)
  • Tests are written in Solidity (like in DappTools)
  • Fast fuzz testing 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
  • Portable (5-10MB) & easy to install without requiring Nix or any other package manager
  • Fast CI with the Foundry GitHub action.

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.

More documentation can be found in the cast package.

Setup

Configuring Foundry

Foundry is designed to be very configurable. You can create a TOML file called foundry.toml place it in the project or any other parent directory, and it will apply the options in that file. See config package for all available options.

Configurations can be arbitrarily namespaced by profiles. Foundry's default configuration is also named default. The selected profile is the value of the FOUNDRY_PROFILE environment variable, or if it is not set, "default". FOUNDRY_ or DAPP_ prefixed environment variables, like FOUNDRY_SRC take precedence, see "Default Profile"

forge init creates a basic, extendable foundry.toml file.

To set all .dapprc env vars run source .dapprc beforehand.

To see all currently set options run forge config, to only see the basic options (as set with forge init) run forge config --basic, this can be used to create a new foundry.toml file with forge config --basic > foundry.toml. By default forge config shows the currently selected foundry profile and its values. It also accepts the same arguments as forge build.

Additional Setup

You can find additional setup guides in the Foundry Book:

Troubleshooting Installation

libusb error when running forge/cast

If you are using the binaries as released, you may see the following error on MacOS:

dyld: Library not loaded: /usr/local/opt/libusb/lib/libusb-1.0.0.dylib

In order to fix this, you must install libusb like so:

brew install libusb

Out of date GLIBC error when running forge from default foundryup install:

If you run into an error resembling the following when using foundryup:

forge: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.29' not found (required by forge)

There are 2 workarounds:

  1. Build from source using the following command:
foundryup -b master
  1. For a solution using Docker, refer to this article: https://kobzol.github.io/rust/ci/2021/05/07/building-rust-binaries-in-ci-that-work-with-older-glibc.html#solution

Contributing

See our contributing guidelines.

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.

To join the Foundry community, you can use our main telegram to chat with us!

To receive help with Foundry, you can use our support telegram to asky any questions you may have.

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.

About

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 98.6%
  • Shell 1.1%
  • Other 0.3%