Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
Your first real deploy. You'll write a Forge script (a small Solidity file with a run() function), run it against Anvil, and get back a contract address. The whole loop — code → compile → deploy → verify — takes under ten seconds locally. The discipline you build here (always deploy locally first) will save you on testnets and mainnet.
A Forge script is a Solidity file that calls vm.startBroadcast() before any state-changing operations; without --broadcast on the CLI, the script only simulates. This simulate-then-broadcast pattern lets you catch constructor failures and unexpected gas spends before you spend real ETH.
// script/DeployHello.s.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "forge-std/Script.sol";
import "../src/Hello.sol";
contract DeployHello is Script {
function run() external returns (Hello) {
vm.startBroadcast
DeployHello.s.sol script exactly as above. Run forge build to compile.anvil in one terminal, keep it running.http://127.0.0.1:8545 with one of anvil's pre-funded private keys. You should see a contract address.greeting from the CLI: cast call <address> 'greeting()(string)' --rpc-url http://127.0.0.1:8545. You should see 'gm'.'hi from anvil' and redeploy. Confirm the new greeting with cast call. You just iterated on a smart contract in ~10 seconds.Use these three in order. Each builds on the one before.
Explain what a Forge deployment script is — it's a `.sol` file, but it doesn't deploy by being compiled. What does `vm.startBroadcast()` actually do?
Walk me through what `forge script` does when I run it: parses the script, connects to the RPC, simulates the transactions, and only broadcasts on `--broadcast`. Why the simulate-then-broadcast pattern?
Deploying the same contract to mainnet as to testnet can cost $100s in gas. What are the best practices for 'dress rehearsing' a deploy — simulation, forking mainnet locally, CI checks — before you send the real transaction?