Convert Figma logo to code with AI

foundry-rs logofoundry

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

8,104
1,672
8,104
689

Top Related Projects

Dapp, Seth, Hevm, and more

14,020

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.

7,162

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.

OpenZeppelin Contracts is a library for secure smart contract development.

3,826

Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Rootstock, Tron and other EVM-compatible blockchains.

5,235

Static Analyzer for Solidity and Vyper

Quick Overview

Foundry is a blazing fast, portable, and modular toolkit for Ethereum application development written in Rust. It provides a comprehensive suite of tools for smart contract development, testing, and deployment, offering a more efficient and developer-friendly alternative to traditional Ethereum development environments.

Pros

  • Extremely fast compilation and testing speeds due to its Rust implementation
  • Highly customizable and extensible with a modular architecture
  • Native support for Solidity and Vyper languages
  • Robust testing framework with built-in fuzzing capabilities

Cons

  • Steeper learning curve for developers not familiar with Rust or command-line tools
  • Less extensive documentation compared to more established tools like Truffle
  • Smaller ecosystem and community support compared to older alternatives
  • May require additional setup for integration with certain IDEs or development workflows

Code Examples

  1. Writing a simple test in Foundry:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import "../src/Counter.sol";

contract CounterTest is Test {
    Counter public counter;

    function setUp() public {
        counter = new Counter();
    }

    function testIncrement() public {
        counter.increment();
        assertEq(counter.number(), 1);
    }
}
  1. Using Foundry's cheatcodes in tests:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import "forge-std/Test.sol";

contract CheatcodeTest is Test {
    function testPrank() public {
        address alice = address(0x1);
        vm.prank(alice);
        // The next call will be made with alice's address
        assertEq(msg.sender, alice);
    }
}
  1. Fuzzing example in Foundry:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import "forge-std/Test.sol";

contract FuzzTest is Test {
    function testFuzz_AdditionIsCommutative(uint256 x, uint256 y) public {
        // This test will run multiple times with different random inputs
        assertEq(x + y, y + x);
    }
}

Getting Started

To get started with Foundry:

  1. Install Foundry:

    curl -L https://foundry.paradigm.xyz | bash
    foundryup
    
  2. Create a new project:

    forge init my_project
    cd my_project
    
  3. Compile the project:

    forge build
    
  4. Run tests:

    forge test
    

For more detailed instructions and advanced usage, refer to the official Foundry documentation.

Competitor Comparisons

Dapp, Seth, Hevm, and more

Pros of Dapptools

  • Mature ecosystem with a comprehensive suite of tools (seth, dapp, hevm)
  • Strong support for formal verification and property-based testing
  • Extensive documentation and established community resources

Cons of Dapptools

  • Steeper learning curve, especially for developers new to Ethereum
  • Slower development cycle and less frequent updates
  • Limited cross-platform support (primarily focused on Unix-like systems)

Code Comparison

Dapptools (using dapp):

dapp test
dapp build
dapp deploy

Foundry:

forge test
forge build
forge create

Key Differences

  • Foundry is written in Rust, while Dapptools is primarily written in Nix and Haskell
  • Foundry offers faster compilation and testing times compared to Dapptools
  • Foundry provides better Windows support and easier installation process
  • Dapptools has a more extensive set of integrated tools, while Foundry focuses on core development features

Both projects aim to improve Ethereum development workflows, but Foundry emphasizes speed and ease of use, while Dapptools offers a more comprehensive toolkit with advanced features for formal verification and property-based testing.

14,020

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.

Pros of Truffle

  • Mature ecosystem with extensive documentation and community support
  • Integrated with other tools like Ganache for local blockchain development
  • Supports multiple programming languages (Solidity, Vyper)

Cons of Truffle

  • Slower compilation and testing compared to Foundry
  • JavaScript-based, which can be less performant for large projects
  • Configuration can be complex for advanced use cases

Code Comparison

Truffle contract deployment:

const MyContract = artifacts.require("MyContract");

module.exports = function(deployer) {
  deployer.deploy(MyContract);
};

Foundry contract deployment:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";

contract MyScript is Script {
    function run() external {
        vm.startBroadcast();
        // Deploy contract here
        vm.stopBroadcast();
    }
}

Foundry offers a more Solidity-centric approach, while Truffle uses JavaScript for deployment scripts. Foundry's syntax is more concise and closely aligned with Solidity development, potentially reducing context switching for developers. However, Truffle's JavaScript-based approach may be more familiar to web developers transitioning into blockchain development.

7,162

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.

Pros of Hardhat

  • Extensive JavaScript ecosystem integration
  • Well-established with a large community and plugin ecosystem
  • Flexible configuration options for diverse project needs

Cons of Hardhat

  • Slower test execution compared to Foundry
  • JavaScript-based, which may be less efficient for some operations
  • Steeper learning curve for developers new to JavaScript/TypeScript

Code Comparison

Hardhat (JavaScript):

const { expect } = require("chai");

describe("Token", function() {
  it("Should return the new token name", async function() {
    const Token = await ethers.getContractFactory("Token");
    const token = await Token.deploy();
    expect(await token.name()).to.equal("MyToken");
  });
});

Foundry (Solidity):

pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "../src/Token.sol";

contract TokenTest is Test {
    function testName() public {
        Token token = new Token();
        assertEq(token.name(), "MyToken");
    }
}

The code comparison showcases the different approaches: Hardhat uses JavaScript with Chai assertions, while Foundry employs Solidity with built-in assertions. Foundry's tests are more concise and closer to the contract language, potentially offering a more intuitive experience for Solidity developers.

OpenZeppelin Contracts is a library for secure smart contract development.

Pros of OpenZeppelin Contracts

  • Comprehensive library of secure, audited smart contract components
  • Widely adopted and battle-tested in production environments
  • Extensive documentation and community support

Cons of OpenZeppelin Contracts

  • Limited to contract development, not a full development environment
  • May require additional tools for testing and deployment

Code Comparison

OpenZeppelin Contracts:

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor() ERC20("MyToken", "MTK") {
        _mint(msg.sender, 1000000 * 10 ** decimals());
    }
}

Foundry:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Test.sol";

contract CounterTest is Test {
    function setUp() public {}

    function testIncrement() public {}
}

Key Differences

  • OpenZeppelin Contracts focuses on providing reusable smart contract components
  • Foundry is a complete Ethereum development environment with testing, deployment, and debugging tools
  • OpenZeppelin Contracts is primarily used for contract development, while Foundry covers the entire development lifecycle
  • Foundry includes a powerful testing framework, whereas OpenZeppelin Contracts requires external testing tools
3,826

Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Rootstock, Tron and other EVM-compatible blockchains.

Pros of Mythril

  • Specialized in security analysis and vulnerability detection for smart contracts
  • Supports multiple blockchain platforms beyond Ethereum
  • Utilizes symbolic execution and SMT solving for in-depth analysis

Cons of Mythril

  • Steeper learning curve for non-security experts
  • May produce false positives in some cases
  • Less frequent updates compared to Foundry

Code Comparison

Mythril (vulnerability detection):

from mythril.mythril import MythrilDisassembler
from mythril.analysis.security import fire_lasers

disassembler = MythrilDisassembler()
contract = disassembler.load_from_solidity("contract.sol")
issues = fire_lasers(contract)

Foundry (testing and development):

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";

contract ContractTest is Test {
    function testExample() public {
        assertTrue(true);
    }
}

Mythril focuses on security analysis, while Foundry provides a comprehensive development environment. Mythril's code demonstrates vulnerability scanning, whereas Foundry's code shows a basic test setup. Foundry offers a more user-friendly approach for general smart contract development, while Mythril excels in specialized security auditing.

5,235

Static Analyzer for Solidity and Vyper

Pros of Slither

  • Specialized in static analysis and vulnerability detection
  • Supports multiple smart contract languages (Solidity, Vyper)
  • Extensive set of built-in detectors for common vulnerabilities

Cons of Slither

  • Limited testing capabilities compared to Foundry
  • Steeper learning curve for configuring and customizing detectors
  • Less focus on development workflow integration

Code Comparison

Slither (running a security analysis):

slither contracts/

Foundry (running tests):

forge test

Slither focuses on static analysis and vulnerability detection, while Foundry is a comprehensive development toolkit. Slither excels in identifying potential security issues across multiple smart contract languages, but has limited testing capabilities. Foundry, on the other hand, offers a more integrated development experience with powerful testing features, but may not provide as extensive security analysis out of the box.

Slither's strength lies in its specialized detectors and ability to analyze contracts written in different languages. Foundry shines in its testing framework, fast compilation, and overall development workflow. While both tools are valuable for smart contract developers, they serve different primary purposes and can be complementary in a comprehensive development and security pipeline.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Foundry logo

Foundry

Github Actions Telegram Chat Telegram Support Foundry

Install | User Book | Developer Docs | Crate Docs

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.
  • Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
  • Chisel: Fast, utilitarian, and verbose solidity REPL.

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

Demo

Installation

See the installation guide in the book.

If you're experiencing any issues while installing, check out Getting Help and the FAQ.

Forge

Features

  • Fast & flexible compilation pipeline
    • Automatic Solidity compiler version detection & installation
    • 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 ethers-solc) and testing.

See the benchmarks below. More benchmarks can be found in the v0.2.0 announcement post and in the Convex Shutdown Simulation repository.

Testing Benchmarks

ProjectForgeDappToolsSpeedup
transmissions11/solmate2.8s6m34s140x
reflexer-labs/geb0.4s23s57.5x
Rari-Capital/vaults0.28s6.5s23x

Note: In the above benchmarks, compilation was always skipped

Compilation Benchmarks

Compilation benchmarks

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

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.

Configuration

Using foundry.toml

Foundry is designed to be very configurable. You can configure Foundry using a file called foundry.toml in the root of your project, or any other parent directory. See config package for all available options.

Configuration can be arbitrarily namespaced by profiles. The default profile is named default (see "Default Profile").

You can select another profile using the FOUNDRY_PROFILE environment variable. You can also override parts of your configuration using FOUNDRY_ or DAPP_ prefixed environment variables, like FOUNDRY_SRC.

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

To see your current configuration, run forge config. To see only 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.

DappTools Compatibility

You can re-use your .dapprc environment variables by running source .dapprc before using a Foundry tool.

Additional Configuration

You can find additional setup and configurations guides in the Foundry Book:

Contributing

See our contributing guidelines.

Getting Help

First, see if the answer to your question can be found in book, or in the relevant crate.

If the answer is not there:

If you want to contribute, or follow along with contributor discussion, you can use our main telegram to chat with us about the development of Foundry!

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.