Working on an Existing Project

Foundry makes developing with existing projects have no overhead.

For this example, we will use PaulRBerg’s foundry-template.

First, clone the project and run forge install inside the project directory.

$ git clone https://github.com/PaulRBerg/foundry-template
$ cd foundry-template
$ forge install
$ bun install # install Solhint, Prettier, and other Node.js deps

We run forge install to install the submodule dependencies that are in the project.

To build, use forge build:

$ forge build --zksync

Compiling 28 files with zksolc and solc 0.8.28
zksolc and solc 0.8.28 finished in 3.12s
Compiler run successful!

And to test, use forge test:

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

No files changed, compilation skipped
2025-01-29T13:28:05.629067Z ERROR foundry_zksync_core::vm::inspect: reverting initiator tx nonce for CALL address=0x1804c8ab1f12e6bbf3894d4083f33e07309d1f38 from=3 to=2 deploy_nonce=2

Ran 3 tests for tests/Foo.t.sol:FooTest
[PASS] testFork_Example() (gas: 3755)
[PASS] testFuzz_Example(uint256) (runs: 1000, μ: 116733, ~: 116733)
[PASS] test_Example() (gas: 119483)
Suite result: ok. 3 passed; 0 failed; 0 skipped; finished in 5.13s (5.12s CPU time)

Ran 1 test suite in 5.13s (5.13s CPU time): 3 tests passed, 0 failed, 0 skipped (3 total tests)

ℹ️ Note

If you are already familiar with the foundry, you will notice the —-zksync flag; we’ll cover it in detail in the following sections.