Foundry profiles let you manage different configurations for your smart contract development workflow. Think of them like "modes" or "settings" that you can switch between depending on your needs.
Profiles in Foundry are named configuration sets that you can use to:
- optimize for different scenarios (gas, testing, deployment)
- use different compiler settings
- configure different testing parameters
- set up different build environments
LazerForge comes packaged with several pre-configured profiles:
forge build --profile default
# or simply
forge buildThe default profile is used when no profile is specified. It includes:
- standard compiler settings
- basic optimization
- normal testing parameters
forge build --profile gasUse this profile when you want to:
- optimize your contracts for gas efficiency
- deploy to production
- compare gas costs between different implementations
forge test --profile CI.fuzzThis profile is designed for CI environments with:
- increased number of fuzz runs (1024)
- more thorough testing
- better coverage
forge build --profile via_irUse this profile when:
- working with complex contracts
- need to use the via-IR pipeline
- dealing with large contract sizes
forge test --profile ffiFor tests that require:
- Foreign Function Interface (FFI)
- external process calls
- system-level interactions
The most common way to use profiles is with the --profile flag:
# Build with gas optimization
forge build --profile gas
# Run tests with CI settings
forge test --profile CI.fuzz
# Deploy with via-IR
forge script script/Deploy.s.sol:DeployScript --profile via_irYou can set a profile for all commands in your current shell:
# Set profile for current shell
export FOUNDRY_PROFILE=gasWhen deploying contracts:
# Deploy with gas optimization
forge script script/Deploy.s.sol:DeployScript --profile gas --rpc-url $RPC_URL
# Deploy with via-IR for complex contracts
forge script script/Deploy.s.sol:DeployScript --profile via_ir --rpc-url $RPC_URL# Normal development
forge build
forge test
# When you need gas optimization
forge build --profile gas# Quick local tests
forge test
# Thorough fuzz testing
forge test --profile CI.fuzz# Standard deployment
forge script script/Deploy.s.sol:DeployScript --rpc-url $RPC_URL
# Gas-optimized deployment
forge script script/Deploy.s.sol:DeployScript --profile gas --rpc-url $RPC_URLYou can add custom profiles to your foundry.toml:
[profile.custom]
# Your custom settings here
optimizer_runs = 200
fuzz_runs = 500Any settings not specified within a profile will use the
defaultsettings. Make sure to override settings fromprofile.defaultwith a custom profile when needed.
-
Use Appropriate Profiles
- Use
gasprofile for production deployments - Use
CI.fuzzfor thorough testing - Use
via_irfor complex contracts
- Use
-
Document Profile Usage
- Add comments in your
foundry.toml - Document profile requirements in your README
- Add comments in your
-
CI/CD Considerations
- Use
CI.fuzzin your CI pipeline - Consider using different profiles for different environments
- Use
-
Development Workflow
- Start with default profile for development
- Switch to
gasprofile before deployment - Use
via_irwhen needed for complex contracts
Profiles can inherit from other profiles using the inherits field. This allows you to build upon existing configurations while adding or overriding specific settings.
[profile.production]
inherits = "default"
optimizer = true
optimizer_runs = 1000Navigation: