Skip to content

Getting Started

This section introduces the forge command-line tool. We will walk through creating a new project, compiling it, and running tests.

Start a new project

To start a new project with Foundry, use the forge init command:

forge init
$ forge init hello_foundry

Now, let’s explore the structure that forge has generated for us:

tree
$ cd hello_foundry
$ tree . -d -L 1
.
├── lib
├── script
├── src
└── test
 
5 directories

Build the project

You can compile the project using forge build:

forge build
$ forge build
Compiling 23 files with Solc 0.8.29
Solc 0.8.29 finished in 481.28ms
Compiler run successful!

Run the tests

To run the tests, use the forge test command:

forge test
$ forge test
No files changed, compilation skipped
 
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 31965, ~: 32354)
[PASS] test_Increment() (gas: 31851)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 38.79ms (33.61ms CPU time)
 
Ran 1 test suite in 137.49ms (38.79ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)