33. Cyfrin Updraft: Foundry Deployment and Scripts
Overview
Section titled “Overview”This external Cyfrin Updraft path teaches the professional way to ship a contract: reproducible, scripted deployment instead of one-off terminal commands. You’ll write a Foundry deploy script, move network-specific values into a HelperConfig so the same code deploys to a local Anvil chain or a public testnet, deploy mocks locally when a real dependency doesn’t exist, add interaction scripts and integration tests, and wrap it all in a Makefile. The recurring security rule threaded through it — never put a real private key in source, shell history, docs, or an AI prompt — is exactly the discipline your capstone deployment needs. The outline, code anatomy, and command flow below are a standalone guide; adapt the final “Capstone Application” steps to your Vendor or DEX.
Video Outline
Section titled “Video Outline”1. Advanced Deploy Scripts · 3 min
Section titled “1. Advanced Deploy Scripts · 3 min”- Create a deployment contract in
script/DeployFundMe.s.sol. - Inherit from Foundry’s
Scriptcontract. - Use
run()as the script entry point. - Wrap transactions with
vm.startBroadcast()andvm.stopBroadcast(). - Return the deployed contract so tests and other scripts can reuse it.
Key idea: a script makes deployment logic executable, testable, and repeatable instead of leaving it as a terminal-only command.
2. Refactoring Tests for Deployment Consistency · 7 min
Section titled “2. Refactoring Tests for Deployment Consistency · 7 min”- Import the deployment script into the test suite.
- Deploy the contract in
setUp()through the same path used outside tests. - Remove differences between test deployment and real deployment.
- Identify hardcoded external contract addresses that prevent local execution.
Key idea: tests should exercise the same constructor configuration and deployment path used by the application.
3. HelperConfig and Mock Price Feeds · 13 min
Section titled “3. HelperConfig and Mock Price Feeds · 13 min”- Store network-specific addresses in a dedicated configuration contract.
- Select configuration with
block.chainid. - Use a real dependency address on a supported testnet.
- Deploy a mock dependency when running against a blank local Anvil chain.
- Pass the selected dependency into the application constructor.
Key idea: deployment scripts should choose dependencies by network without changing application source code.
4. Idempotent Local Mock Deployment · 8 min
Section titled “4. Idempotent Local Mock Deployment · 8 min”Watch part one · Watch part two
- Move mock creation into the configuration workflow.
- Check for
address(0)before deploying a new mock. - Reuse an existing local configuration when one is already available.
- Avoid deploying duplicate dependencies each time configuration is read.
Key idea: an idempotent script can run repeatedly without creating unnecessary or inconsistent infrastructure.
5. Interaction Scripts and Integration Tests · 15 min
Section titled “5. Interaction Scripts and Integration Tests · 15 min”- Create
Interactions.s.solwith separate scripts for application actions. - Resolve the most recent deployment with
foundry-devops. - Broadcast state-changing calls such as funding and withdrawal.
- Separate unit tests from integration tests.
- Test an end-to-end sequence that deploys, interacts, and checks final balances.
- Understand why Foundry FFI requires special caution when enabled.
Key idea: interaction scripts are reusable operational clients for a deployed contract, while integration tests verify that those operations work together.
6. Automating Commands with a Makefile · 8 min
Section titled “6. Automating Commands with a Makefile · 8 min”- Replace long, error-prone commands with named targets.
- Add shortcuts for build, test, local deployment, and testnet deployment.
- Load RPC and explorer configuration from environment variables.
- Combine deployment, broadcast, and contract verification in a repeatable command.
- Keep network-specific values out of committed source files.
Key idea: the Makefile becomes the documented command interface for the project’s common development and deployment operations.
Optional Extensions
Section titled “Optional Extensions”zkSync DevOps · 15 min
Section titled “zkSync DevOps · 15 min”Explore conditional tests and deployment behavior across EVM and zkSync environments. This is optional for the course capstone unless zkSync is the selected deployment target.
Git and GitHub Packaging · 16 min
Section titled “Git and GitHub Packaging · 16 min”Review repository initialization, .gitignore, secret exclusion, and project publishing. The important security rule is to verify that .env, keystores, private keys, RPC credentials, and generated sensitive cache data are not committed.
Deployment Script Anatomy
Section titled “Deployment Script Anatomy”Use this structure as a reading guide rather than code to paste without review:
import {Script} from "forge-std/Script.sol";import {MyContract} from "../src/MyContract.sol";
contract DeployMyContract is Script { function run() external returns (MyContract deployed) { vm.startBroadcast(); deployed = new MyContract(); vm.stopBroadcast(); }}The script has four responsibilities:
- Import the contract and Foundry scripting tools.
- Resolve network-specific constructor inputs.
- Broadcast only the transactions that must be sent onchain.
- Return or record the deployed address for later interactions.
Command Flow
Section titled “Command Flow”# Build and test before deploymentforge buildforge test
# Simulate the script without sending transactionsforge script script/DeployMyContract.s.sol:DeployMyContract --rpc-url "$RPC_URL"
# Broadcast only after reviewing the simulationforge script script/DeployMyContract.s.sol:DeployMyContract \ --rpc-url "$RPC_URL" \ --account "$FOUNDRY_ACCOUNT" \ --sender "$DEPLOYER_ADDRESS" \ --broadcastUse a Foundry keystore account or another secure signer workflow. Do not place a real private key in source files, shell history, documentation, or AI prompts.
What to Understand Before Moving On
Section titled “What to Understand Before Moving On”- The difference between script simulation and
--broadcast. - Why
run()is the standard Foundry script entry point. - Where deployment receipts and broadcast artifacts are stored.
- How
block.chainidselects network configuration. - When a local mock should replace a live external dependency.
- How interaction scripts locate and call a deployed contract.
- Why deployment, interaction, and integration testing are separate concerns.
- How automation reduces manual errors without replacing transaction review.
Capstone Application
Section titled “Capstone Application”Adapt the sequence to the Vendor or DEX project:
- Create one deployment script for the selected capstone contract.
- Move token, oracle, or network addresses into a configuration layer.
- Add local mocks only for dependencies that do not exist on Anvil.
- Create at least one interaction script for a core workflow such as buying, selling, adding liquidity, or swapping.
- Run unit and integration tests before any broadcast.
- Simulate the deployment, inspect the trace, and then deploy to the selected testnet.
- Record the contract address, chain ID, deployment transaction, constructor arguments, and verification status in the README.
Open the Course
Section titled “Open the Course”Cyfrin Updraft: Foundry Fundamentals
Course segment: Foundry Fund Me, with a focus on reproducible deployment and interaction workflows.
This lesson is a curated path through several videos in the Foundry Fund Me section. The recommended core sequence is approximately 54 minutes. Course titles and durations were reviewed against Updraft in July 2026.
