FAQ
Common questions about Foundry.
General
What is Foundry?
Foundry is a fast, portable, and modular toolkit for Ethereum development written in Rust. It includes:
- Forge — Build, test, and deploy smart contracts
- Cast — Interact with the chain from the command line
- Anvil — Local Ethereum node for development
- Chisel — Interactive Solidity REPL
How do I install Foundry?
Use foundryup:
$ curl -L https://foundry.paradigm.xyz | bash
$ foundryupSee Installation for details.
How do I update Foundry?
Run foundryup again:
$ foundryupTo install a specific version:
$ foundryup --version nightly-abc123How do I get help with a command?
All Foundry tools support --help:
$ forge --help
$ forge test --help
$ cast --help
$ anvil --help
$ chisel --helpSee the CLI reference for full command docs.
Forge
How do I run a specific test?
Use --match-test:
$ forge test --match-test test_TransferUse --match-contract for a specific contract:
$ forge test --match-contract TokenTestHow do I see console.log output?
Use verbosity level 2 or higher:
$ forge test -vvWhy are my tests slow?
Common causes:
- Forking without caching — Enable fork caching with
--fork-cache - Too many fuzz runs — Reduce
fuzz.runsinfoundry.tomlfor local development - Large contracts — Consider splitting tests into separate files
How do I debug a failing test?
Use the interactive debugger:
$ forge test --debug test_MyTestOr increase verbosity to see the trace:
$ forge test --match-test test_MyTest -vvvvSee Debugging for more.
How do I fork mainnet in tests?
Set --fork-url or configure it in foundry.toml:
$ forge test --fork-url https://ethereum.reth.rs/rpcOr in foundry.toml:
[profile.default]
fork_url = "https://ethereum.reth.rs/rpc"How do I run tests in parallel?
Tests run in parallel by default. To control parallelism:
$ forge test --jobs 4Set to 1 for sequential execution (useful for debugging):
$ forge test --jobs 1Cast
How do I call a contract function?
Use cast call for read-only calls:
$ cast call $CONTRACT "balanceOf(address)" $ADDRESSUse cast send for state-changing transactions:
$ cast send $CONTRACT "transfer(address,uint256)" $TO $AMOUNT --private-key $KEYHow do I decode transaction data?
Use cast 4byte-decode:
$ cast 4byte-decode 0xa9059cbb000000000000000000000000...How do I convert between units?
Use cast to-wei and cast from-wei:
$ cast to-wei 1 ether
# 1000000000000000000
$ cast from-wei 1000000000000000000
# 1.000000000000000000Anvil
How do I get test ETH?
Anvil pre-funds 10 accounts with 10,000 ETH each. List them:
$ anvil
# Shows accounts and private keys on startupHow do I impersonate an account?
Start Anvil with auto-impersonation:
$ anvil --auto-impersonateOr impersonate a specific account via RPC:
$ cast rpc anvil_impersonateAccount $ADDRESSHow do I reset the chain state?
Use the RPC method:
$ cast rpc anvil_resetOr restart Anvil.
How do I mine blocks manually?
Disable auto-mining and mine manually:
$ anvil --no-mining
# In another terminal:
$ cast rpc anvil_mine 10 # Mine 10 blocksChisel
How do I access my project's contracts?
Chisel automatically loads your project. Import and use contracts:
➜ import {Counter} from "src/Counter.sol";
➜ Counter c = new Counter();
➜ c.increment();How do I fork in Chisel?
Start with a fork:
$ chisel --fork-url https://ethereum.reth.rs/rpcOr fork during a session:
➜ !fork https://ethereum.reth.rs/rpcHow do I save my session?
Use the !save command:
➜ !save my-sessionLoad it later:
$ chisel load my-sessionWas this helpful?
