Skip to content
Logo

Getting Started

Foundry is a fast, portable, and modular toolkit for Ethereum development. After installing Foundry, you have access to four tools:

ToolPurposeReference
forgeBuild, test, debug, deploy, and verify smart contractsReference
castInteract with contracts, send transactions, and query chain dataReference
anvilRun a local Ethereum node with forking capabilitiesReference
chiselSolidity REPL for rapid prototypingReference

Quick start with Forge

Create and test a smart contract in under 30 seconds:

Create a new project

$ forge init hello_foundry
$ cd hello_foundry

Build contracts

$ forge build

Run tests

$ forge test

The generated project includes a Counter contract and test:

$ forge test
Compiling...
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.sol

Local development with Anvil

Start a local Ethereum node:

$ anvil

This creates 10 pre-funded test accounts. Fork mainnet state for realistic testing:

$ anvil --fork-url https://eth.merkle.io

Interact with chains using Cast

Query blockchain data:

Check an address balance
$ cast balance vitalik.eth --ether --rpc-url https://eth.merkle.io
Get the latest block number
$ cast block-number --rpc-url https://eth.merkle.io
Call a contract function
$ cast call 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 "totalSupply()" --rpc-url https://eth.merkle.io

Send transactions to your local Anvil node:

Send ETH using an Anvil test account
$ cast send 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \
    --value 1ether \
    --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Prototype with Chisel

Start the Solidity REPL:

$ chisel

Write 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: 42

Type !help to see available commands.

Next steps