Important: Note on learning by building

A workflow-focused introduction to Understanding the Real Smart Contract Development Workflow - Discover the iterative nature of smart contract development beyond simplified tutorials. Learn the typical cycle of coding, testing, deploying, debugging, and refactoring crucial for building secure applications.

Solidity Developer

Foundry Fundamentals

1. Introduction
An advanced guide to Building a Smart Contract Lottery with Foundry - Leverage Chainlink VRF for provable randomness and Chainlink Automation for hands-off operation to create a decentralized raffle. Implement industry best practices like NatSpec and pinned dependencies for a robust portfolio project. Duration: 6min
2. Smart contract lottery - Project setup
A foundational guide to Initializing the Raffle Smart Contract - Create the basic `Raffle.sol` file, add NatSpec documentation, and define core raffle functions. Implement an immutable entrance fee pattern using a constructor and getter for gas efficiency. Duration: 6min
3. Solidity style guide
A foundational guide to Structuring Solidity Smart Contracts - Discover the recommended layout for Solidity files and contract elements like state variables, events, and functions. Enhance readability, maintainability, and auditability by adopting standardized conventions for better collaboration and security. Duration: 2min
4. Creating custom errors
A gas-optimizing guide to Efficient Error Handling with Solidity Custom Errors - Understand the high gas cost of traditional `require` string reverts and embrace modern custom errors. Learn the preferred `if/revert CustomError()` pattern for cheaper, clearer error handling in Solidity. Duration: 8min
5. Smart contracts events
A state-managing guide to Tracking Raffle Players and Introducing Solidity Events - Learn to track raffle participants by storing player addresses in a `payable` array within your Solidity contract. Understand and implement Solidity events to signal state changes efficiently for off-chain applications and front-ends. Duration: 12min
6. Random numbers - Block Timestamp
A foundational guide to Implementing Time Checks in the Raffle Smart Contract - Learn to enforce time intervals in your Solidity functions using `block.timestamp`, immutable, and storage variables. Add essential time-based logic to the `pickWinner` function to control raffle execution frequency. Duration: 5min
7. Random numbers - Introduction to Chainlink VRF
A practical introduction to Integrating Chainlink VRF for Verifiable Randomness - Tackle the challenge of on-chain randomness using Chainlink VRF's secure, verifiable solution and its v2/v2.5 subscription model. Learn the end-to-end integration process, from setting up a subscription to implementing the consumer contract logic. Duration: 10min
8. Implement the Chainlink VRF
An integration-focused guide to Implementing Chainlink VRF v2.5 Requests - Learn to initiate Chainlink VRF v2.5 random number requests from your Foundry smart contract via the Subscription method. Set up dependencies, configure contract parameters, and implement the call to the VRF Coordinator. Duration: 23min
9. Implementing Vrf Fulfil
An essential guide to Implementing the Chainlink VRF `fulfillRandomWords` Callback - Learn why implementing the `fulfillRandomWords` callback is mandatory when inheriting from `VRFConsumerBaseV2Plus`. Understand the VRF request-response flow and the role of `rawFulfillRandomWords` in securely delivering randomness. Duration: 8min
10. The modulo operation
A practical guide to Using the Modulo Operator for Random Winner Selection - Learn how the Modulo operator (%) reliably maps large random numbers from Chainlink VRF to valid array indices for fair winner selection. Implement secure prize transfers in Solidity using `.call` and robust error handling. Duration: 6min
11. Implementing the lottery state - Enum
A foundational guide to Managing Smart Contract States with Solidity Enums - Understand the importance of managing distinct contract phases, especially during asynchronous operations like Chainlink VRF calls. Learn how to use Solidity enums for clearer, safer, and more maintainable state logic compared to simple booleans. Duration: 6min
12. Quiz 12 Quiz
Questions: 10
13. Lottery restart - Resetting an Array
A state-management guide to Resetting Raffle State for the Next Round - Discover the gas-efficient way to clear the players array in Solidity using `new address payable[](0)`. Properly reset raffle state, timestamp, and emit winner events to ensure a clean start for the next round. Duration: 2min
14. Important: Note on learning by building
A workflow-focused introduction to Understanding the Real Smart Contract Development Workflow - Discover the iterative nature of smart contract development beyond simplified tutorials. Learn the typical cycle of coding, testing, deploying, debugging, and refactoring crucial for building secure applications. Duration: 2min
15. The CEI method - Checks, Effects, Interactions
A foundational guide to Secure Smart Contract Development: The Checks, Effects, Interactions (CEI) Pattern - Master the crucial CEI pattern to structure Solidity functions for improved security and gas efficiency. Learn why ordering Checks, Effects, and Interactions is vital for preventing reentrancy attacks. Duration: 4min
16. Quiz 16 Quiz
Questions: 7
17. Introduction to Chainlink Automation
A simplified guide to Automating Your Smart Contracts with Chainlink Automation - Discover how Chainlink Automation provides decentralized triggers for your contracts. Focus on the streamlined time-based trigger configuration via the UI, simplifying development compared to custom logic implementations. Duration: 17min
18. Implementing Chainlink Automation
A practical guide to Automating Your Smart Contract with Chainlink Automation - Learn to implement the core `checkUpkeep` and `performUpkeep` functions required by Chainlink Automation for decentralized task scheduling. Understand the off-chain condition checking and on-chain execution pattern, including internal validation nuances. Duration: 12min
19. Custom Error
A clarity-boosting guide to Enhancing Solidity Error Reporting with Custom Error Parameters - Learn to define Solidity custom errors that accept parameters for richer revert information. Include crucial contract state like balance, counts, or status codes directly in your error messages to simplify debugging. Duration: 2min
20. Mid section recap
A Chainlink-focused review of Smart Contract Lottery Mechanics - Understand how Chainlink VRF provides verifiable randomness for fair winner selection in `Raffle.sol`. Learn how Chainlink Automation enables automated lottery draws by monitoring contract state and triggering key functions. Duration: 3min
21. Test and deploy the lottery smart contract pt.1
A foundational introduction to Introduction to Smart Contract Testing - Understand why rigorous testing is vital for immutable smart contracts handling assets. Learn a strategy using `forge script` for deployment first, enabling consistent multi-environment testing setups. Duration: 2min
22. Deploy Script
A network-aware guide to Deploying Contracts with Foundry Scripts and HelperConfig - Master Foundry deployment scripts (`.s.sol`) for automated, programmatic contract deployment. Implement the `HelperConfig` pattern to manage network-specific parameters, ensuring adaptability across environments like Sepolia and local Anvil. Duration: 11min
23. Deploy a mock Chainlink VRF
A configuration-focused guide to Deploying Mock Contracts for Local Development - Enhance your HelperConfig.sol to automatically deploy mock contracts like Chainlink VRFCoordinatorV2_5Mock when on local networks. Use Foundry cheatcodes to enable realistic local testing without testnet dependencies. Duration: 7min
24. Test and deploy the lottery smart contract pt.2
A network-aware guide to Finalizing a Dynamic Foundry Deployment Script - Implement a `HelperConfig` contract to manage network-specific parameters, ensuring seamless deployment across local, testnet, and mainnet. Automatically deploy mocks or use live configurations based on the chain ID. Duration: 4min
25. Quiz 25 Quiz
Questions: 8
26. Setup the tests
A foundational guide to Setting Up Your First Foundry Test for a Smart Contract - Learn to structure Foundry tests using `unit`/`integration` folders and write essential boilerplate including imports and state variables. Implement the `setUp` function for deployment via scripts and create your first basic assertion test. Duration: 8min
27. Headers
A convenience-focused introduction to Automatically Generating Solidity Headers - Discover the optional `headers` command-line tool designed to quickly create perfectly formatted Solidity comment headers. Learn how it automatically generates and copies headers to your clipboard, improving code organization and readability. Duration: 1min
28. Adding more tests
A hands-on guide to Writing Your First Foundry Tests: The Raffle Contract - Write your first unit tests for a Raffle contract using Foundry, focusing on the `enterRaffle` function. Learn to use `vm.prank`, `vm.expectRevert`, and `vm.deal` to test custom error reverts and successful player recording. Duration: 7min
29. Testing events
An essential guide to Testing Solidity Events in Foundry - Learn Foundry's unique three-step workflow using `vm.expectEmit` to verify correct event emissions. Understand how to check specific parameters and the necessity of copying event definitions into your test contracts. Duration: 5min
30. Using vm.roll and vm.warp
A cheatcode-driven guide to Testing State Transitions with vm.warp and vm.roll - Learn to manipulate block time and number using `vm.warp` and `vm.roll` in Foundry tests. Verify contract behavior in specific states, like preventing actions during a `CALCULATING` phase, using `vm.expectRevert`. Duration: 6min
31. Subscribing to events
A troubleshooting guide to Debugging and Fixing VRF InvalidConsumer Errors in Foundry - Diagnose the common `InvalidConsumer` error encountered when integrating Chainlink VRF in Foundry tests. Learn how to refactor deployment scripts to programmatically create VRF subscriptions, resolving issues in local development environments. Duration: 18min
32. Creating the subscription UI
A foundational walkthrough to Creating a VRF Subscription via the Chainlink UI - Learn the manual steps to create a Chainlink VRF subscription using the web UI for context, even if you plan to automate later. Covers getting testnet LINK and understanding the `subscriptionId` needed for programmatic interaction. Duration: 4min
33. Fund subscription
An automated approach to Funding Your Chainlink VRF Subscription Using a Foundry Script - Create a Foundry script to programmatically fund your Chainlink VRF subscription with LINK tokens. Handle differences between local mocks (`fundSubscription`) and live testnets (`transferAndCall`) using `HelperConfig`. Duration: 15min
34. Adding a consumer
A scripting-centric approach to Resolving the Chainlink VRF InvalidConsumer Error in Foundry Tests - Tackle the Chainlink VRF `InvalidConsumer` error within Foundry tests by creating a dedicated interaction script. Automate adding your deployed contract as an authorized consumer to ensure VRF requests succeed during setup. Duration: 13min
35. Even More Tests
A coverage-focused guide to Improving Raffle.sol Test Coverage: Targeting checkUpkeep - Learn to write targeted Foundry unit tests for the `checkUpkeep` function using the Arrange-Act-Assert pattern. Utilize cheatcodes like `vm.warp`, `vm.roll`, and `vm.prank` to verify conditions where upkeep isn't needed. Duration: 5min
36. Quiz 36 Quiz
Questions: 8
37. Coverage Report
An insightful walkthrough of Pinpointing Untested Code with Foundry's Debug Coverage Report - Go beyond basic coverage percentages by generating and analyzing Foundry's detailed debug report. Learn to identify specific untested lines and branches to strategically improve your test suite's effectiveness. Duration: 4min
38. Testing and refactoring the performUpkeep
A precise guide to Testing the `performUpkeep` Function - Learn to verify `performUpkeep` executes only when `checkUpkeep` returns true using Foundry cheatcodes. Master testing specific revert conditions, including custom errors with parameters via `vm.expectRevert` and `abi.encodeWithSelector`. Duration: 7min
39. Refactoring events data
An event-focused lesson to Capturing and Verifying Solidity Events in Foundry - Learn to emit custom events in Solidity and capture them in Foundry tests using `vm.recordLogs`. Decode event parameters from the `Vm.Log` struct and enhance test readability with modifiers. Duration: 9min
40. Intro to fuzz testing
A robustness-enhancing introduction to Introduction to Stateless Fuzz Testing in Foundry - Discover the power of stateless fuzz testing in Foundry to move beyond limited, hardcoded test inputs. Learn how to convert unit tests to automatically probe function logic with random values, enhancing contract reliability. Duration: 9min
41. One Big Test
A comprehensive guide to Crafting End-to-End Unit Tests in Foundry - Master E2E unit testing by simulating a full raffle lifecycle from entry to payout via VRF callback. Utilize cheatcodes, mock contracts, and event logging to verify complex interactions and state changes. Duration: 13min
42. Forked test environment and dynamic private keys
A practical guide to Ensuring Foundry Test Success on Forks - Resolve common failures when moving Foundry tests from local Anvil to network forks by addressing account permission issues. Utilize network-specific accounts via `vm.startBroadcast(address)` and skip mock-dependent tests using a `skipFork` modifier. Duration: 12min
43. Creating integration tests
A comprehensive introduction to Moving Beyond Unit Tests with Foundry Integration - Learn why unit tests alone aren't sufficient and how integration tests verify script-contract interactions. Write tests that execute deployment/interaction scripts to validate system behavior and boost script coverage. Duration: 4min
44. Deploy the lottery on the testnet pt.1
An end-to-end guide to Deploying Your Lottery to Sepolia - Master Sepolia testnet deployment with Foundry and Makefiles for streamlined commands. Integrate Chainlink VRF and Automation to observe your smart contract lottery run end-to-end. Duration: 16min
45. Implementing console log in your smart contract
An insightful guide to Debugging Solidity with In-Contract Console Logging - Discover how to use Foundry's built-in `console.log` from `forge-std` for in-contract debugging during tests. Learn to view output with verbosity flags and understand the critical need to remove logs before deployment. Duration: 1min
46. Debug using forge test
An advanced introduction to Diving Deep: Introduction to the Foundry Opcode Debugger - Learn to use Foundry's Opcode Debugger for precise analysis of low-level EVM execution. Step through opcodes, inspect stack/memory/gas usage, and leverage this tool for deep optimization and security auditing. Duration: 1min
47. Section recap
A comprehensive recap to Building a Provably Fair Decentralized Lottery - Revisit core `Raffle.sol` contract logic, Chainlink VRF/Automation integration, and the crucial Checks-Effects-Interactions security pattern. Explore advanced Foundry use cases for sophisticated deployment/configuration scripts and comprehensive testing with cheatcodes. Duration: 6min
48. Summary Quiz Quiz
Questions: 11

Course Overview

About the course

What you'll learn

Foundryup, Foundry Forge, and Anvil

Blockchain Oracles

How to create local Blockchain testnets

How to verify a smart contract

How to write and run smart contract tests

Course Description

Who is this course for?

  • Software engineers
  • Web3 developers
  • Blockchain security researchers

Potential Careers

Security researcher

$49,999 - $120,000 (avg. salary)

Smart Contract Engineer

$100,000 - $150,000 (avg. salary)

Web3 developer

$60,000 - $150,000 (avg. salary)

Web3 Developer Relations

$85,000 - $125,000 (avg. salary)

Smart Contract Auditor

$100,000 - $200,000 (avg. salary)

Meet your instructors

Patrick Collins

Patrick Collins

Founder at Cyfrin

Web3 engineer, educator, and Cyfrin co-founder. Patrick's smart contract development and security courses have helped hundreds of thousands of engineers kickstarting their careers into web3.

Guest lecturers:

Richard Gottleber

Richard Gottleber

Developer relations at Chainlink

Vasiliy Gualoto

Vasiliy Gualoto

Developer relations at ThirdWeb

Last updated on May 27, 2025