Forge
Forge compiles, tests, and deploys Solidity smart contracts. It's the core development tool in the Foundry suite.
Core workflows
Build and test
Compile contracts and run tests with traces.
Advanced testing
Fuzz, invariant, and fork-based testing workflows.
Deploy and verify
Ship contracts with scripts and verify on explorers.
Debug and optimize
Trace failures and track gas usage.
Key capabilities
| Feature | Description |
|---|---|
| Compilation | Compile contracts with configurable Solidity versions and optimization |
| Testing | Write tests in Solidity with fuzzing, forking, and gas reporting |
| Scripting | Deploy and interact with contracts using Solidity scripts |
| Verification | Verify source code on Etherscan and other explorers |
| Analysis | Inspect bytecode, storage layouts, and gas usage |
Common workflows
Build your project
$ forge buildSolc 0.8.33 finished in 1.07s
Compiler run successful!Run all tests
$ forge testCompiling...
No files changed, compilation skipped
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 26879, ~: 29289)
[PASS] test_Increment() (gas: 28783)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 5.39ms (5.16ms CPU time)
Ran 1 test suite in 9.40ms (5.39ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)Run tests with verbose output
$ forge test -vvvvCompiling...
No files changed, compilation skipped
Ran 1 test for test/OwnerUpOnly.t.sol:OwnerUpOnlyTest
[PASS] test_IncrementAsOwner() (gas: 29808)
Traces:
[29808] OwnerUpOnlyTest::test_IncrementAsOwner()
├─ [2407] OwnerUpOnly::count() [staticcall]
│ └─ ← [Return] 0
├─ [20460] OwnerUpOnly::increment()
│ └─ ← [Stop]
├─ [407] OwnerUpOnly::count() [staticcall]
│ └─ ← [Return] 1
└─ ← [Stop]
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 288.76µs (54.88µs CPU time)
Ran 1 test suite in 7.73ms (288.76µs CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)Deploy via script
$ forge script script/Deploy.s.sol --broadcast --rpc-url $RPC_URLVerify a deployed contract
$ forge verify-contract $ADDRESS src/Counter.sol:Counter --etherscan-api-key $KEYLearn more
- Building contracts — Compilation, artifacts, and optimization
- Testing — Writing and running tests
- Scripting — Deployment and on-chain interactions
- Debugging — Traces, debugger, and troubleshooting
- Gas tracking — Snapshots and reports
- Linting — Code style enforcement
- Reference — Full CLI reference
Was this helpful?
