Dec 14, 2022

EVM Development Toolchains

1. Foundry

Introduction to Foundry: Ethereum Development Toolkit

Foundry is a versatile toolkit designed for Ethereum application development, written in Rust. It comprises the following components:

Forge: Ethereum Testing Framework

Similar to Truffle, Hardhat, and DappTools, Forge serves as an Ethereum testing framework. It facilitates testing smart contracts and application logic within the Ethereum ecosystem.

Cast: Versatile Ethereum Interaction Tool

Cast operates as a Swiss army knife for engaging with EVM (Ethereum Virtual Machine) smart contracts. It enables users to send transactions and access chain data conveniently.

Anvil: Local Ethereum Node

Resembling Ganache and Hardhat Network, Anvil functions as a local Ethereum node. It provides a testing environment for Ethereum-based applications, aiding in development and testing processes.

Chisel: Solidity REPL (Read-Eval-Print Loop)

Chisel stands as a rapid, utilitarian, and verbose Solidity REPL. It offers an interactive environment for Solidity programming, allowing developers to experiment, test code snippets, and execute Solidity commands swiftly.

Installation Guide for Foundry on Mac

Precompiled Binaries using Foundryup

  1. Install Foundryup: Open your terminal and run the following command:
curl -L https://foundry.paradigm.xyz | bash

Follow the on-screen instructions to complete the installation. This will make the 'foundryup' command available in your CLI.

  1. Install Foundry tools: Run 'foundryup' to install the latest (nightly) precompiled binaries including Forge, Cast, Anvil, and Chisel. Use foundryup --help for more options, such as installing from a specific version or commit.

Building from Source

Prerequisites
  • Rust Compiler and Cargo: Install with rustup.rs.
  • Windows: Additionally, install Visual Studio with the "Desktop Development With C++" Workloads option.
Building Steps
  1. Using Foundryup Flags:
foundryup --branch master
foundryup --path path/to/foundry
  1. Using Cargo Command:
cargo install --git https://github.com/foundry-rs/foundry --profile local --locked forge cast chisel anvil
  1. Manually Building from Repository:

    # Clone the repository
    git clone https://github.com/foundry-rs/foundry.git
    cd foundry

    # Install Forge
    cargo install --path ./crates/forge --profile local --force --locked

    # Install Cast
    cargo install --path ./crates/cast --profile local --force --locked

    # Install Anvil
    cargo install --path ./crates/anvil --profile local --force --locked

    # Install Chisel
    cargo install --path ./crates/chisel --profile local --force --locked

These steps should guide you through installing Foundry on your Mac, whether through precompiled binaries using Foundryup or building from the source code.

First Steps with Foundry

This section provides an overview of the 'forge' command line tool. Let's dive into creating a new project, compiling, and testing it.

Creating a New Project

To initiate a new project with Foundry, use 'forge init':

$ forge init hello_foundry
cd hello_foundry
tree . -d -L 1

.
├── lib
├── script
├── src
└── test

4 directories

Building the Project
Build the project using forge build:

$ forge build

Compiling 10 files with 0.8.16
Solc 0.8.16 finished in 3.97s
Compiler run successful

$ forge test

No files changed, compilation skipped

Running 2 tests for test/Counter.t.sol:CounterTest
[PASS] testIncrement() (gas: 28312)
[PASS] testSetNumber(uint256) (runs: 256, μ: 27376, ~: 28387)
Test result: ok. 2 passed; 0 failed; finished in 24.43ms

2. Hardhat

References

  1. https://book.getfoundry.sh/getting-started/installation

  2. https://github.com/foundry-rs/foundry/tree/master


Thanks for reading! If you want to see future content, you can follow me on Twitter or get connected over at LinkedIn.


Support My Content

If you find my content helpful, consider supporting a humanitarian cause (building homes for elderly people in rural Terai region of Nepal) that I am planning with your donation:

Ethereum (ETH)

0xb0b1B20062DA9Dd7BaA4D5b088DF49dbe4b46fF2

Thank you for your support!