
Chapter 0x9: Editing foundry.toml for Compiler Settings, Network Settings, Test Optimizations & Deploying Contracts Best Guide🚀
Introduction
Editing foundry.toml : If you’re diving into Foundry for smart contract development, you’ve probably come across the foundry.toml
file. But what exactly is it, and why is it so important? 🤔 Well, this file is the configuration heart of Foundry, allowing developers to tweak settings for compilation, networks, testing, and contract deployment.
Table of Contents
In this guide, we’ll break down:
✅What is a .toml file in Foundry?
✅Foundry config overview
✅Compiler settings and multiple Solidity versions
✅Network configurations
✅Test optimization in Foundry
✅Deploying contracts with Foundry
✅Common errors and troubleshooting
So, whether you’re a beginner or just looking for some optimizations, this guide will help you master foundry.toml
like a pro! 😎
🔍 What is a .toml
File in Foundry?

.toml
File in Foundry?A .toml
file is a configuration file format used by Foundry to store settings in a simple, readable structure. It defines everything from compiler versions to network configurations, testing options, and deployment strategies.
When working with Foundry, foundry.toml
is your go-to file for tweaking project settings without modifying your Solidity contracts. Let’s explore its key sections! 🚀
⚙️ Foundry Config Overview

Foundry’s configuration file is structured with various sections, each controlling different aspects of your project. Below is a high-level overview:
[profile.default]
solc_version = "0.8.20" # Foundry compiler settings
evm_version = "paris" # Foundry evm version
optimizer = true # Enable Solidity optimizer
optimizer_runs = 200 # Optimize for how many runs
fuzz_runs = 500 # Foundry fuzz config
Each section in foundry.toml
allows us to fine-tune how our contracts are compiled, tested, and deployed. Let’s dive deeper into each of these settings. 🔥
🛠 Compiler Settings in foundry.toml

foundry.toml
Compiler settings are crucial for optimizing contract performance and compatibility. Foundry lets you specify the Solidity compiler version, EVM version, and optimizer settings.
Example Configuration:
solc_version = "0.8.20" # Foundry multiple solc version support
evm_version = "paris" # Ethereum upgrade compatibility
optimizer = true
optimizer_runs = 500
Key Settings:
- solc_version: Determines which Solidity compiler version to use.
- evm_version: Defines the Ethereum Virtual Machine (EVM) compatibility.
- optimizer: Enables Solidity’s optimizer for gas-efficient code.
- optimizer_runs: Controls how much optimization should be performed.
Troubleshooting:
If you encounter an error like:
foundry config error: unknown evm version: cancun for setting evm_version
It means your EVM version is not supported. Check Foundry compiler settings GitHub for the latest updates.
🌐 Network Settings in foundry.toml

foundry.toml
When deploying smart contracts, you need to configure networks correctly. Foundry allows you to specify different networks in foundry.toml
.
Example Configuration:
[rpc_endpoints]
mainnet = "https://eth-mainnet.alchemyapi.io/v2/YOUR_API_KEY"
sepolia = "https://sepolia.infura.io/v3/YOUR_API_KEY"
Adding Custom Networks:
Want to deploy on Base or other L2 solutions? Here’s how:
[rpc_endpoints]
base = "https://mainnet.base.org"
This ensures your deployments and transactions are sent to the correct network.
🧪 Test Optimization in Foundry

Testing is a critical part of smart contract development, and Foundry provides powerful tools to optimize your tests.
Example Test Optimization Settings:
[fuzz]
runs = 1000 # Foundry fuzz config for more reliable tests
Using forge test
Run tests with:
forge test
If you see:
Forge Nothing to compile
Make sure your contracts are up-to-date by running:
forge build
🚀 Deploying Contracts with Foundry

Once testing is done, it’s time to deploy your smart contract with Foundry. Foundry provides an easy way to do this.
Deployment Steps:
- Compile the contract:
forge build
- Deploy using a private key:
forge create --rpc-url https://eth-mainnet.alchemyapi.io/v2/YOUR_API_KEY --private-key 0xYOUR_PRIVATE_KEY ContractName
- Verify the contract on Etherscan:
forge verify-contract --chain mainnet --etherscan-api-key YOUR_API_KEY --contract-name ContractName --constructor-args 0x...
Deploying on Base:
To deploy on Base:
forge create --rpc-url https://mainnet.base.org --private-key 0xYOUR_PRIVATE_KEY ContractName
🏆 Advanced Deployment: OpenZeppelin Foundry Upgrades

If you want to deploy upgradeable smart contracts, Foundry supports OpenZeppelin upgrades.
Install OpenZeppelin Upgradeable Contracts:
forge install openzeppelin/contracts-upgradeable
Deploy Upgradeable Contract:
forge create --rpc-url https://mainnet.infura.io/v3/YOUR_API_KEY --private-key 0xPRIVATE_KEY UpgradeableContract
This ensures that your contract can be upgraded later using OpenZeppelin’s proxy pattern.
🛠 Foundry Common Errors & Fixes
Here are some common issues and their solutions:
1. Forge Nothing to compile
error
- Run
forge build
to ensure your contracts are up-to-date.
2. foundry config error: unknown evm version: cancun
- Ensure your Foundry version supports the EVM upgrade.
3. Deployment failed due to missing private key
- Set your private key in an
.env
file or pass it as an argument.
📖 Conclusion
By now, you should have a solid understanding of editing foundry.toml
, configuring compiler and network settings, optimizing tests, and deploying contracts with Foundry. 🚀 Whether you’re building simple Solidity contracts or deploying to Ethereum, Base, or L2 solutions, Foundry makes the process smooth and efficient.
With this guide, you’re ready to optimize your Foundry workflow and deploy smart contracts like a pro! 💪
Got questions? Drop them in the comments below! Happy coding! 🎉
LEARN SOLIDITY PROGTAMMING TUTORIAL FROM BASIC TO ADVANCED