First Steps with Foundry
This section provides an overview of the forge
command line tool. We demonstrate how to create a new project, compile, and test it.
To start a new project with Foundry, use forge init
:
$ forge init hello_foundry
Let’s check out what forge
generated for us:
$ cd hello_foundry
$ tree . -d -L 1
.
├── lib
├── script
├── src
└── test
4 directories
We can build the project with forge build
:
$ forge build
Compiling 27 files with Solc 0.8.19
Solc 0.8.19 finished in 1.08s
Compiler run successful!
And run the tests with forge test
:
$ forge test
No files changed, compilation skipped
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 31054, ~: 31288)
[PASS] test_Increment() (gas: 31303)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 5.23ms (4.91ms CPU time)
Ran 1 test suite in 6.42ms (5.23ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
💡 Tip
You can always print help for any subcommand (or their subcommands) by adding
--help
at the end.
You can watch these beginner tutorials if you are a visual learner.