Skip to content
Logo

Forge

Forge compiles, tests, and deploys Solidity smart contracts. It's the core development tool in the Foundry suite.

Core workflows

Key capabilities

FeatureDescription
CompilationCompile contracts with configurable Solidity versions and optimization
TestingWrite tests in Solidity with fuzzing, forking, and gas reporting
ScriptingDeploy and interact with contracts using Solidity scripts
VerificationVerify source code on Etherscan and other explorers
AnalysisInspect bytecode, storage layouts, and gas usage

Common workflows

Build your project
$ forge build
Solc 0.8.34 finished in 1.13s Compiler run successful!
Run all tests
$ forge test
Compiling... No files changed, compilation skipped Ran 2 tests for test/Counter.t.sol:CounterTest [PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 27112, ~: 29289) [PASS] test_Increment() (gas: 28783) Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 5.28ms (5.06ms CPU time) Ran 1 test suite in 8.96ms (5.28ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
Run tests with verbose output
$ forge test -vvvv
Compiling... 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 275.64µs (45.00µs CPU time) Ran 1 test suite in 7.72ms (275.64µ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_URL
Verify a deployed contract
$ forge verify-contract $ADDRESS src/Counter.sol:Counter --etherscan-api-key $KEY

Learn more