First Steps with Foundry-ZKsync

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-ZKsync, 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 --zksync:

$ forge build --zksync

Compiling 27 files with zksolc and solc 0.8.26
zksolc and solc 0.8.26 finished in 3.94s
Compiler run successful!

And run the tests with forge test --zksync:

$ forge test --zksync
Compiling 25 files with Solc 0.8.27
Solc 0.8.27 finished in 922.92ms
Compiler run successful!

No files changed, compilation skipped

Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, ΞΌ: 721067, ~: 671196)
[PASS] test_Increment() (gas: 526627)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 3.39s (3.38s CPU time)

Ran 1 test suite in 3.40s (3.39s 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.