Getting Started
Foundry is a fast, portable, and modular toolkit for Ethereum development. After installing Foundry, you have access to four tools:
| Tool | Purpose | Reference |
|---|---|---|
forge | Build, test, debug, deploy, and verify smart contracts | Reference |
cast | Interact with contracts, send transactions, and query chain data | Reference |
anvil | Run a local Ethereum node with forking capabilities | Reference |
chisel | Solidity REPL for rapid prototyping | Reference |
Quick start with Forge
Create and test a smart contract in under 30 seconds:
The generated project includes a Counter contract and test:
$ forge testCompiling...
No files changed, compilation skipped
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 49967, ~: 52529)
[PASS] test_Increment() (gas: 51847)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 6.01ms (5.72ms CPU time)
Ran 1 test suite in 9.14ms (6.01ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)Deploy using a Forge script:
$ forge script script/Counter.s.solLocal development with Anvil
Start a local Ethereum node:
$ anvilThis creates 10 pre-funded test accounts. Fork mainnet state for realistic testing:
$ anvil --fork-url https://eth.merkle.ioInteract with chains using Cast
Query blockchain data:
Check an address balance
$ cast balance vitalik.eth --ether --rpc-url https://eth.merkle.ioGet the latest block number
$ cast block-number --rpc-url https://eth.merkle.ioCall a contract function
$ cast call 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 "totalSupply()" --rpc-url https://eth.merkle.ioSend transactions to your local Anvil node:
Send ETH using an Anvil test account
$ cast send 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \
--value 1ether \
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80Prototype with Chisel
Start the Solidity REPL:
$ chiselWrite and execute Solidity interactively:
➜ uint256 x = 42;
➜ x * 2
Type: uint256
├ Hex: 0x54
└ Decimal: 84
➜ function double(uint256 n) public pure returns (uint256) { return n * 2; }
➜ double(21)
Type: uint256
└ Decimal: 42Type !help to see available commands.
Next steps
Was this helpful?
