Foundry

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

Components

Foundry consists of several key components, each designed to streamline different aspects of Ethereum development:

  • Forge : Ethereum testing framework, similar to Truffle, Hardhat, and DappTools.
  • Cast : A versatile command-line tool for interacting with EVM smart contracts, sending transactions, and retrieving chain data.
  • Anvil : A local Ethereum node, comparable to Ganache or Hardhat Network.
  • Chisel : A fast and utilitarian Solidity REPL for rapid development.

Documentation

For detailed guides and usage instructions, refer to the following resources:

Installation

To install Foundry, follow the installation guide in the Foundry Book. If you encounter any issues, refer to the FAQ.

Forge

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 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][foundry-gha]

Performance

Foundry's Forge is optimized for speed, both in compiling and testing. Benchmark comparisons demonstrate significant speed improvements over similar tools:

Testing Benchmarks

ProjectForgeDappToolsSpeedup
[transmissions11/solmate][solmate]2.8s6m34s140x
[reflexer-labs/geb][geb]0.4s23s57.5x
[Rari-Capital/vaults][vaults]0.28s6.5s23x

Note: Compilation was skipped in these benchmarks.

Compilation Benchmarks

Compilation benchmarks Compilation benchmarks

Takeaway: Forge compilation is consistently faster by a factor of 1.7-11.3x, depending on caching.

Cast

Cast is a versatile command-line tool for interacting with Ethereum applications. It provides functionalities for sending transactions, interacting with smart contracts, and retrieving chain data.

Configuration

Using foundry.toml

Foundry is designed to be highly configurable. Configuration is managed through the foundry.toml file, which can be located in the root of your project or any parent directory.

To initialize a basic foundry.toml file:

forge init

To view the current configuration:

forge config

For additional setup and configurations, refer to the Foundry Book.

DappTools Compatibility

You can reuse your .dapprc environment variables by running:

source .dapprc

Similar Projects

Rustfinity.com

Links

  1. Home
  2. Learn Rust
  3. Get Started
  4. Practice Rust
  5. Challenges
  6. Tutorials
  7. Blog
  8. Open source
  9. Learn Gleam

Socials

  1. GitHub
  2. X

Legal

  1. Privacy Policy
  2. Terms of Service