πŸš€ Deploying Contracts in Foundry

Now that we’ve mastered unit, fuzz, invariant, and differential testing, it’s time to deploy our battle-tested smart contracts to real networks. Foundry makes deployment simple, scriptable, and even allows you to deploy to multiple chains in one command.


πŸ”„ 1. Remapping Dependencies (Understanding remappings) πŸ”„

❓ The Problem:

When you use external libraries like OpenZeppelin, Foundry doesn’t know where to find them by default. You might write:

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

But Foundry has no idea what @openzeppelin means. It’s just a path alias.

βœ… The Solution: Remappings

You tell Foundry: β€œHey, whenever you see @openzeppelin, go look in the lib/openzeppelin-contracts folder.”


πŸ“‚ Step-by-Step Setup

A. Install the Dependency

First, install OpenZeppelin (or any library) using Forge:

forge install OpenZeppelin/openzeppelin-contracts

This downloads the contracts into your lib/ directory.

B. Configure Remappings

Edit your foundry.toml file: