Creating a New Project
Initialize the project
To start a new project with Foundry, use forge init:
$ forge init hello_foundryThis creates a new directory hello_foundry from the default template. This also initializes a new git repository.
Navigate to the project directory
Move into your newly created project:
cd hello_foundryExplore the project structure
Let's check what the default template looks like:
$ tree . -d -L 2
.
├── lib
│ └── solady
├── script
├── src
└── test
6 directoriesThe default template comes with one dependency installed: Forge Standard Library. This is the preferred testing library used for Foundry projects. Additionally, the template also comes with an empty starter contract and a simple test.
Build the project
Compile your contracts:
$ forge build
Compiling 23 files with Solc 0.8.30
Solc 0.8.30 finished in 541.51ms
Compiler run successful!Run the tests
Execute the test suite:
$ forge test
No files changed, compilation skipped
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 28045, ~: 29289)
[PASS] test_Increment() (gas: 28783)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 6.86ms (6.57ms CPU time)
Ran 1 test suite in 10.62ms (6.86ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)You'll notice that two new directories have popped up: out and cache.
The out directory contains your contract artifact, such as the ABI, while the cache is used by forge to only recompile what is necessary.
