
Chapter 0x1: What is Foundry
What is Foundry: If you’ve been dabbling in blockchain development or smart contracts, you’ve likely come across tools like Hardhat or Truffle. But there’s a new kid on the block that’s rapidly gaining attention among developers: Foundry. Today, we’ll dive into what Foundry is, why it’s becoming a favorite for smart contract testing, and how to get started with it. Whether you’re a total beginner or have some experience, this guide will set the foundation for mastering Foundry.
Table of Contents
What is Foundry?

Foundry is an Ethereum development framework designed to make working with smart contracts more efficient, secure, and developer-friendly. Unlike other frameworks, Foundry emphasizes speed, simplicity, and versatility. It’s particularly well-suited for testing and debugging smart contracts, making it a go-to choice for developers focused on quality and security.
Key Components of Foundry:
- Forge:
- The core development tool in Foundry, used for compiling, deploying, and testing smart contracts.
- Think of Forge as your Swiss Army knife for Ethereum development.
- Cast:
- A command-line tool for interacting with Ethereum.
- Use Cast to call smart contract functions, send transactions, and fetch blockchain data.
- Anvil:
- A local Ethereum node simulator.
- Perfect for testing contracts in an isolated environment without relying on public testnets.
Why is Foundry Special?
- Blazing Fast Compilation: Foundry uses the Rust-based
solc
compiler, which is faster than most alternatives. - Native Solidity Testing: Unlike some frameworks that require JavaScript for testing, Foundry allows you to write tests directly in Solidity.
- Minimal Setup: No need for complex configurations; Foundry works out of the box.
- Cross-Tool Integration: Foundry can be seamlessly integrated with tools like Hardhat and Truffle for hybrid workflows.
Why Should You Use Foundry?

Foundry isn’t just another framework; it’s a game-changer for Ethereum developers. Here’s why:
1. Developer Efficiency
With Foundry’s command-line simplicity and native Solidity support, you’ll spend less time configuring your environment and more time building and testing.
2. Robust Testing Capabilities
Foundry makes testing a breeze. Its built-in tools support unit tests, integration tests, and even fuzz testing—a critical feature for identifying vulnerabilities in smart contracts.
3. High Performance
Foundry’s tools are designed with speed in mind. Compiling, deploying, and testing contracts happens almost instantaneously, allowing for a seamless development experience.
4. Security First
Foundry’s tools are tailored to enhance the security of your smart contracts. With features like fuzz testing and mainnet forking, it’s easier to identify and patch vulnerabilities before they’re exploited.
5. Future-Proofing
As the Ethereum ecosystem evolves, Foundry is keeping pace with regular updates and new features. By learning Foundry, you’re equipping yourself with skills that will remain relevant for years.
Installing Foundry: A Quick Start Guide

Before diving into Foundry, you’ll need to install it. Follow these steps to set up Foundry on your machine:
Step 1: Install Rust
Foundry relies on Rust for its underlying functionality. To install Rust:
- Open your terminal.
- Run the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Follow the on-screen instructions to complete the installation.
- Verify Rust installation:
rustc --version
Step 2: Install Foundry Solidity
Once Rust is installed, you can install Foundry using the foundryup
script:
- Run the following command in your terminal:
curl -L https://foundry.paradigm.xyz | bash
- Restart your terminal or run:
source ~/.bashrc
- Verify Foundry installation:
foundryup forge --version
That’s it! Foundry is now installed and ready to use.
Understanding Foundry’s Workflow

Foundry’s workflow is straightforward and efficient. Here’s a quick overview of how it works:
1. Initialize a Project
Start by creating a new Foundry project:
forge init my-first-foundry-project
This command creates a new project folder with all the necessary boilerplate code.
2. Write Your Smart Contract
Navigate to the src
folder and create your Solidity contract file. For example:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract HelloWorld {
string public greeting = "Hello, World!";
function setGreeting(string memory _greeting) public {
greeting = _greeting;
}
}
3. Compile Smart Contract Using Foundry
Use Forge to compile your contract:
forge build
This generates the compiled artifacts in the out
directory.
4. Write and Run Tests
Write your tests in the test
folder using Solidity. For example:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/Test.sol";
import "../src/HelloWorld.sol";
contract HelloWorldTest is Test {
HelloWorld hw;
function setUp() public {
hw = new HelloWorld();
}
function testInitialGreeting() public {
assertEq(hw.greeting(), "Hello, World!");
}
function testSetGreeting() public {
hw.setGreeting("Hi, Foundry!");
assertEq(hw.greeting(), "Hi, Foundry!");
}
}
Run the tests using:
forge test
Next Steps
Now that you have a basic understanding of Foundry and its setup, you’re ready to dive deeper. In the next chapter, we’ll explore how to write and test your first smart contract in more detail. You’ll learn about best practices for structuring your code, writing test cases, and debugging.
Stay tuned—your journey into mastering Foundry has just begun!
FAQs
Q: Is Foundry better than Hardhat?
A: It depends on your needs. Foundry excels in testing speed and native Solidity support, while Hardhat offers more plugins and JavaScript integration.
Q: Do I need prior experience to use Foundry?
A: No! Foundry is beginner-friendly and this tutorial series is designed to guide you step-by-step.
Q: Can Foundry be used with existing Hardhat projects?
A: Yes, Foundry can integrate with other frameworks like Hardhat, allowing you to use the best of both worlds.
Q: Is Foundry free to use?
A: Absolutely! Foundry is open-source and free for everyone.
Congratulations on taking the first step into the world of Foundry! Follow this series daily to build your expertise and become a pro at testing smart contracts with Foundry. Foundry testing tutorial for beginners, Foundry testing tutorial GitHub, Foundry test examples, How to write Foundry test, Forge test, Foundry Tutorial, Foundry invariant testing, and Foundry Solidity Tutorials will all be covered in upcoming chapters!
Read More : Solidity Programming