Foundry Setup for Smart Contract Development
We integrate Foundry into your smart contract development pipeline. Unlike Hardhat, the Rust-based Foundry delivers up to 50x speed improvement on tests, but it requires proper configuration of profiles and dependencies. Without this, you risk unstable builds or missing reentrancy issues during testing.
A blockchain developer's life is endless iterations: compile, run tests, find a bug, fix, run again. Foundry makes this cycle dozens of times faster, but to unlock its potential, you need the right configuration. We will set it up for you turnkey. In 5 years of work, we have configured Foundry for 50+ projects—from simple ERC-20s to complex DeFi protocols on L2.
Why Foundry Is Faster Than Hardhat
Foundry is written in Rust and compiles Solidity directly via solc, eliminating intermediate layers. Tests run in a native environment, and fuzzing works out of the box. The result is 10–50x faster compilation and testing on typical DeFi projects. As noted in the Foundry documentation, a benchmark on a project with 200 tests shows 3 seconds versus 45 seconds for Hardhat.
Installation and Basic Configuration
The foundryup command installs the latest toolchain. A project is initialized via forge init my-project. The basic structure:
my-project/ ├── foundry.toml ├── src/ ├── test/ ├── script/ └── lib/ The foundry.toml file is the heart of the configuration. We set up two profiles: a fast one for local development and a deeper one for CI.
| Parameter | [profile.default] | [profile.ci] |
|---|---|---|
| fuzz.runs | 1000 | 10000 |
| invariant.runs | 256 | 1000 |
| invariant.depth | 500 | 1000 |
This approach lets you test basic logic in minutes locally and obtain reliable results on CI.
[profile.default] src = "src" out = "out" libs = ["lib"] solc = "0.8.24" optimizer = true optimizer_runs = 200 fuzz = { runs = 1000 } invariant = { runs = 256, depth = 500 } [profile.ci] fuzz = { runs = 10000 } invariant = { runs = 1000, depth = 1000 } How to Set Up a CI Profile in Foundry?
The CI profile requires more aggressive fuzzing and depth for invariant tests. Configure it separately in foundry.toml and run via forge test --profile ci -vvv. In the CI pipeline we also enable --gas-report and additional Slither checks.
Dependencies via forge install
We pull in OpenZeppelin, forge-std, and other libraries.
forge install OpenZeppelin/openzeppelin-contracts forge install foundry-rs/forge-std After installation, add remappings:
remappings = [ "@openzeppelin/=lib/openzeppelin-contracts/", "forge-std/=lib/forge-std/src/", ] Dependencies are stored as git submodules—this is the Foundry standard, ensuring reproducibility.
Tip: How to avoid remapping conflicts
If multiple libraries export the same paths, use priority in foundry.toml: remappings are processed in declaration order. Always verify compilation after adding a new dependency.How to Set Up Fork Testing with Anvil?
Anvil is a local node with mainnet fork capability. This is a key feature for integration tests.
anvil --fork-url $MAINNET_RPC --fork-block-number 19000000 --chain-id 1 You get a copy of the mainnet state at a specific block without mocks. Our experience shows that fork tests catch non-obvious errors that unit tests miss. In one project, an invariant test found three logical errors in 20 minutes that manual tests missed: in a deposit → withdraw → deposit chain, totalSupply diverged by 1 wei due to rounding.
Fuzz and Invariant Tests
Fuzzing works automatically—just pass a random parameter to the test.
function testFuzz_Deposit(uint256 amount) public { amount = bound(amount, 1, 1e27); token.mint(alice, amount); vm.prank(alice); vault.deposit(amount); assertEq(vault.balanceOf(alice), amount); } Invariant tests verify that system invariants hold after any sequence of calls.
function invariant_TotalSupplyEqualsDeposits() public { assertEq(vault.totalSupply(), vault.totalDeposits()); } CI Integration (GitHub Actions)
We set up a pipeline that runs tests with the CI profile on every commit.
- name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 - name: Run tests run: forge test --profile ci -v env: FOUNDRY_ETH_RPC_URL: ${{ secrets.MAINNET_RPC }} What's Included in the Setup
- Configuration of foundry.toml with default/ci profiles
- Installation and remapping of dependencies (OpenZeppelin, forge-std)
- Setup of Anvil with mainnet fork for integration tests
- Writing basic fuzz and invariant tests
- CI pipeline with GitHub Actions (GitLab, CircleCI on request)
- Documentation on the flags and commands used
Timelines
Setting up Foundry with dependencies, profiles, and CI takes 2 to 6 hours depending on project complexity. This includes writing template tests and debugging the fork. The cost is determined individually after analysis.
Why Choose Our Setup?
We don't just copy template configurations—we analyze your project structure, select optimal fuzzing and invariant parameters, and set up gas reporting. Over 5 years of blockchain development experience and 50+ successful projects guarantee that your configuration will work reliably.
Contact us to get a consultation on Foundry setup for your project. We'll assess your tasks and propose the optimal solution.
Note: Setup costs depend on the scope of work and are discussed individually.







