How cyfrin/foundry-smart-contract-lottery-cu works
Project type and purpose
• This is a Solidity-based “Smart Contract Lottery” project built with Foundry.
• Purpose: demonstrate how to write, test (unit + forked), deploy, and interact with a raffle/lottery contract that uses Chainlink VRF for randomness and Chainlink Automation for upkeep.
File structure
• Top-level config & infra
• .env.example, foundry.toml, Makefile, GitHub Actions workflow
• .gitmodules → on-chain dependencies vendored under lib/
• img/ → screenshots for documentation
• Libraries (lib/)
• chainlink-brownie-contracts, forge-std, foundry-devops, solmate
• Source (src/)
• src/sublesson/ → your raffle contract(s) & helper config scripts
• Scripts (script/)
• Deployment & helper scripts written in Solidity (via foundry-devops)
• Tests (test/)
• unit/ → pure local tests
• staging/ → forked tests against Sepolia RPC URL
• mocks/ → Chainlink VRF mocks
Extract architecture insights from the README
• Developer workflow:
• forge build / forge test / forge coverage
• make anvil → boots a local Anvil node
• make deploy → runs deployment scripts against local or remote network
• External dependencies & services:
• Chainlink VRF (randomness)
• Chainlink Automation (upkeep)
• Sepolia node (via Alchemy RPC)
• Etherscan API (contract verification)
Main components & their interactions
a. Developer CLI / CI
• forge & cast (Foundry toolchain)
• Makefile shortcuts
• GitHub Actions CI pipeline
b. Local On-Chain Environment
• Anvil (local Ethereum node)
• Deployed Raffle contract
• VRFCoordinatorMock contract
c. Remote Network
• Sepolia RPC node (Alchemy)
• Deployed Raffle contract
d. Off-Chain Scripts
• Deployment scripts (script/HelperConfig.s.sol, script/Deploy.s.sol)
• Interaction scripts using cast
e. External Oracles/Services
• Chainlink VRF Coordinator (randomness provider)
• Chainlink Automation (upkeep registry)
• Etherscan (verification)
Architectural patterns & design principles
• Modular contract design: Raffle contract separated from subscription/config logic in HelperConfig
• Dependency vendoring: all required solidity libraries in lib/
• Multi-tier testing: pure unit, forked staging tests
• Infrastructure-as-Code: deployment orchestrated via scripts in Solidity (foundry-devops)