Creating a New Project

To start a new project with Foundry-ZKsync, use forge init:

$ forge init hello_foundry

This creates a new directory hello_foundry from the default template. This also initializes a new git repository.

If you want to create a new project using a different template, you would pass the --template flag, like so:

$ forge init --zksync --template https://github.com/foundry-rs/forge-template hello_template

For now, let’s check what the default template looks like:

$ cd hello_foundry
$ tree . -d -L 1
.
β”œβ”€β”€ lib
β”œβ”€β”€ script
β”œβ”€β”€ src
└── test

5 directories

The default template comes with two dependencies installed: Forge Standard Library and Forge-ZKsync 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.

Let’s build the project:

$ forge build
Compiling 22 files with Solc 0.8.19
Solc 0.8.19 finished in 564.64ms
Compiler run successful!

And run the tests:

$ forge test
No files changed, compilation skipped

Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, ΞΌ: 32307, ~: 32385)
[PASS] test_Increment() (gas: 31874)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 10.19ms (9.83ms CPU time)

Ran 1 test suite in 11.06ms (10.19ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)

You’ll notice that two new directories have popped up: out, zkout and cache.

The out directory contains your EVM contract artifact, such as the ABI, the zkout directory contains the zkEVM contract artifacts, while the cache is used by forge to only recompile what is necessary.