Introduction to Foundry
Foundry is a smart contract development toolchain. Foundry manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the command-line and via Solidity scripts.Prerequisites
You will need the Rust compiler and Cargo, the Rust package manager. The easiest way to install both is with rustup.rs.Using Foundryup
Foundryup is the Foundry toolchain installer. You can find more about it here. Open your terminal and run the following command:foundryup by itself will install the latest (nightly) precompiled binaries: forge, cast, anvil, and chisel.
Create a new project using Forge
To start a new project with Foundry, use:If you initializing project in an already initialized git repo use:
Adding a dependency
To add a dependency, use:Remapping dependencies
Forge can remap dependencies to make them easier to import. Forge will automatically try to deduce some remappings for you- To import from
forge-stdwe would write: importforge-std/Contract.sol; - To import from
ds-testwe would write: importds-test/Contract.sol; - To import from
solmatewe would write: importsolmate/Contract.sol; - To import from
weird-erc20we would write: importweird-erc20/Contract.sol;
remappings.txt file in the root of your project.
Removing dependencies
You can remove dependencies usingAdding Celo specific config to foundry.toml
Add the following configuration to foundry.toml file in the root level of your project.
Deploying contract
Forge can deploy smart contracts to a given network using: The below example deploysCounter contract at location src/Counter.sol in the project to the Celo Sepolia Testnet.
Notice the contract name after
:, this is because a single solidity file can have multiple contracts.It is recommended to use --verify flag so that the contract gets verified right after deployment, this requires etherscan configuration in the foundry.toml file.

