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
DocumentationGenerate a Vocs API site from Solidity source and NatSpec comments
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
BindingsGenerate typed Alloy crates and Solidity JSON helpers

Common workflows

Build your project
$ forge build
Solc 0.8.36 finished in 855.62ms
Compiler run successful!
warning[empty-block]: empty function body
   ╭▸ script/Counter.s.sol:10:29

10     function setUp() public {}
                             ━━

help: ]8;;https://getfoundry.sh/forge/linting/empty-block\https://getfoundry.sh/forge/linting/empty-block]8;;\
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, μ: 50747, ~: 52565)
[PASS] test_Increment() (gas: 51847)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 4.09ms (3.85ms CPU time)
Ran 1 test suite in 8.57ms (4.09ms 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: 59372)
Traces:
  [59372] OwnerUpOnlyTest::test_IncrementAsOwner()
    ├─ [2407] OwnerUpOnly::count() [staticcall]
    │   └─ ← [Return] 0
    ├─ [43524] OwnerUpOnly::increment()
    │   └─ ← [Stop]
    ├─ [2407] OwnerUpOnly::count() [staticcall]
    │   └─ ← [Return] 1
    └─ ← [Stop]
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 287.16µs (62.42µs CPU time)
Ran 1 test suite in 6.97ms (287.16µ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