Infrastructure
Foundry consists of:
Need help getting started with Foundry? Read the š Foundry Book!
High-Performance Compilation
Advanced Testing
console.sol
for flexible debug logging.Powerful Runtime Features
Streamlined CI/CD
Getting started is very easy:
Install foundryup
:
curl -L https://foundry.paradigm.xyz | bash
Next, run foundryup
.
It will automatically install the latest version of the precompiled binaries: forge
, cast
, anvil
, and chisel
.
foundryup
Done!
For additional details see the installation guide in the Foundry Book.
If you're experiencing any issues while installing, check out Getting Help and the FAQ.
Forge is quite fast at both compiling (leveraging solc
with foundry-compilers) and testing.
See the benchmarks below. Older benchmarks against DappTools can be found in the v0.2.0 announcement post and in the Convex Shutdown Simulation repository.
Project | Type | Forge 1.0 | Forge 0.2 | DappTools | Speedup |
---|---|---|---|---|---|
vectorized/solady | Unit / Fuzz | 0.9s | 2.3s | - | 2.6x |
morpho-org/morpho-blue | Invariant | 0.7s | 1m43s | - | 147.1x |
morpho-org/morpho-blue-oracles | Integration (Cold) | 6.1s | 6.3s | - | 1.04x |
morpho-org/morpho-blue-oracles | Integration (Cached) | 0.6s | 0.9s | - | 1.50x |
transmissions11/solmate | Unit / Fuzz | 2.7s | 2.8s | 6m34s | 1.03x / 140.0x |
reflexer-labs/geb | Unit / Fuzz | 0.2s | 0.4s | 23s | 2.0x / 57.5x |
In the above benchmarks, compilation was always skipped
Takeaway: Forge dramatically outperforms the competition, delivering blazing-fast execution speeds while continuously expanding its robust feature set.
Takeaway: Forge compilation is consistently faster than Hardhat by a factor of 2.1x
to 5.2x
, depending on the amount of caching involved.
Forge helps you build, test, fuzz, debug and deploy Solidity contracts.
The best way to understand Forge is to simply try it (in less than 30 seconds!).
First, let's initialize a new counter
example repository:
forge init counter
Next cd
into counter
and build :
forge build
[ā ] Compiling...
[ā ] Compiling 27 files with Solc 0.8.28
[ā ] Solc 0.8.28 finished in 452.13ms
Compiler run successful!
Let's test our contracts:
forge test
[ā ] Compiling...
No files changed, compilation skipped
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 31121, ~: 31277)
[PASS] test_Increment() (gas: 31293)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 5.35ms (4.86ms CPU time)
Ran 1 test suite in 5.91ms (5.35ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
Finally, let's run our deployment script:
forge script script/Counter.s.sol
[ā ] Compiling...
No files changed, compilation skipped
Script ran successfully.
Gas used: 109037
If you wish to simulate on-chain transactions pass a RPC URL.
Run forge --help
to explore the full list of available subcommands and their usage.
More documentation can be found in the forge section of the Foundry Book.
Cast is a Swiss Army knife for interacting with Ethereum applications from the command line.
Here are a few examples of what you can do:
Check the latest block on Ethereum Mainnet:
cast block-number --rpc-url https://eth.merkle.io
Check the Ether balance of vitalik.eth
cast balance vitalik.eth --ether --rpc-url https://eth.merkle.io
Replay and trace a transaction
cast run 0x9c32042f5e997e27e67f82583839548eb19dc78c4769ad6218657c17f2a5ed31 --rpc-url https://eth.merkle.io
Optionally, pass --etherscan-api-key <API_KEY>
to decode transaction traces using verified source maps, providing more detailed and human-readable information.
Run cast --help
to explore the full list of available subcommands and their usage.
More documentation can be found in the cast section of the Foundry Book.
Anvil is a fast local Ethereum development node.
Let's fork Ethereum mainnet at the latest block:
anvil --fork-url https://eth.merkle.io
You can use those same cast
subcommands against your anvil
instance:
cast block-number
Run anvil --help
to explore the full list of available features and their usage.
More documentation can be found in the anvil section of the Foundry Book.
Chisel is a fast, utilitarian, and verbose Solidity REPL.
To use Chisel, simply type chisel
.
chisel
From here, start writing Solidity code! Chisel will offer verbose feedback on each input.
Create a variable a
and query it:
ā uint256 a = 123;
ā a
Type: uint256
ā Hex: 0x7b
ā Hex (full word): 0x000000000000000000000000000000000000000000000000000000000000007b
ā Decimal: 123
Finally, run !source
to see a
was applied:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
import {Vm} from "forge-std/Vm.sol";
contract REPL {
Vm internal constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
/// @notice REPL contract entry point
function run() public {
uint256 a = 123;
}
}
Run chisel --help
to explore the full list of available features and their usage.
More documentation can be found in the chisel section of the Foundry Book.
Foundry is highly configurable, allowing you to tailor it to your needs. Configuration is managed via a file called foundry.toml
located in the root of your project or any parent directory. For a full list of configuration options, refer to the config package documentation.
Profiles and Namespaces
default
. Learn more in the Default Profile section.FOUNDRY_PROFILE
environment variable.FOUNDRY_
(e.g., FOUNDRY_SRC
).You can find additional setup and configurations guides in the Foundry Book and in the config crate:
See our contributing guidelines.
First, see if the answer to your question can be found in the Foundy Book, or in the relevant crate.
If the answer is not there:
If you want to contribute, or follow along with contributor discussion, you can use our main telegram to chat with us about the development of Foundry!
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in these crates by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
abigen
macros.