JetJadeja / foundry

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

foundry

Github Actions Telegram Chat 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.

demo

Forge

cargo install --git https://github.com/gakonst/foundry --bin forge --locked

More documentation can be found in the forge package and in the CLI README.

Features

  1. Fast & flexible compilation pipeline:
    1. Automatic Solidity compiler version detection & installation (under ~/.svm)
    2. Incremental compilation & caching: Only changed files are re-compiled
    3. Parallel compilation
    4. Non-standard directory structures support (e.g. can build Hardhat repos)
  2. Tests are written in Solidity (like in DappTools)
  3. Fast fuzz Tests with shrinking of inputs & printing of counter-examples
  4. Fast remote RPC forking mode leveraging Rust's async infrastructure like tokio
  5. Flexible debug logging:
    1. Dapptools-style, using DsTest's emitted logs
    2. Hardhat-style, using the popular console.sol contract
  6. Portable (5-10MB) & easy to install statically linked binary without requiring Nix or any other package manager
  7. 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 to cast and forge.
  • 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.
  • 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.

License:Apache License 2.0


Languages

Language:Rust 99.7%Language:Solidity 0.3%