Deploy a mock Chainlink VRF

A practical guide to Deploying Mock Contracts for Local Development - Learn how to use `HelperConfig.sol` and Foundry cheatcodes to automatically deploy mock Chainlink contracts like VRFCoordinatorV2_5Mock. This enables reliable testing of external contract interactions in your local development environment.

Solidity Developer

Foundry Fundamentals

1. Introduction
An advanced project walkthrough for Introduction to Building a Smart Contract Lottery with Foundry - Construct a sophisticated, automated lottery leveraging Foundry, Chainlink VRF for fairness, and Chainlink Automation for hands-off operation. Focuses on best practices, Sepolia deployment, and building a standout portfolio piece. Duration: 6min
2. Smart contract lottery - Project setup
A step-by-step introduction to Creating the Raffle Contract Foundation - Begin building a Raffle smart contract by creating the file, adding standard Solidity boilerplate, and documenting with NatSpec. Learn to define an immutable entrance fee set via the constructor and create basic function outlines. Duration: 6min
3. Solidity style guide
A structured overview of Mastering Solidity Code Layout: Readability, Maintainability, and Security - Discover the recommended layout for Solidity files and contracts based on official style guides. Understand the correct order for pragmas, imports, state variables, and functions to boost code clarity and collaboration. Duration: 2min
4. Creating custom errors
An efficient lesson on Handling Errors Efficiently with Solidity Custom Reverts - Replace costly `require` string reverts with modern, gas-saving custom errors in Solidity. Learn the optimal `if/revert` pattern, naming conventions, and why custom errors are superior. Duration: 8min
5. Smart contracts events
A practical guide to Tracking Raffle Players and Introducing Solidity Events - Learn how to store participant addresses using `payable` arrays in your smart contract. Discover the crucial role of Solidity events for efficient off-chain signaling and implement one for player entries. Duration: 12min
6. Random numbers - Block Timestamp
A step-by-step guide to Implementing Time Checks in the Raffle Smart Contract - Build the time-checking mechanism for the `pickWinner` function in a Solidity raffle contract. Understand how to define intervals, track the last timestamp, and use `block.timestamp` to control execution timing. Duration: 5min
7. Random numbers - Introduction to Chainlink VRF
A practical walkthrough for Implementing Chainlink VRF for Smart Contracts - Overcome on-chain randomness limits with Chainlink VRF's verifiable, off-chain solution and subscription model. Learn the full integration process: funding, deployment, configuration, requesting randomness, and handling the callback securely. Duration: 10min
8. Implement the Chainlink VRF
A practical walkthrough of Implementing the Chainlink VRF v2.5 Request - Integrate Chainlink VRF v2.5 into a Foundry project, focusing on the request process via the Subscription method. Learn to set up dependencies, configure contract state/constructor, and initiate random number requests. Duration: 23min
9. Implementing Vrf Fulfil
An essential guide to Implementing the Chainlink VRF `fulfillRandomWords` Callback - Discover why `fulfillRandomWords` is mandatory when inheriting from `VRFConsumerBaseV2Plus` and how it securely receives random values. Understand the role of `override` and the complete Chainlink VRF request-response flow. Duration: 8min
10. The modulo operation
A practical explanation of Using the Modulo Operator to Select a Random Winner in Solidity - Discover how the Modulo operator (%) reliably converts large random numbers into valid array indices for fair winner selection. Learn its application within a Solidity raffle smart contract, alongside secure Ether transfer methods. Duration: 6min
11. Implementing the lottery state - Enum
An insightful guide to Managing Smart Contract States with Solidity Enums - Discover why simple booleans fall short for managing complex smart contract states, especially with asynchronous actions. Learn how Solidity enums provide a clear, type-safe, and maintainable way to control contract flow. Duration: 6min
12. Lottery restart - Resetting an Array
A vital lesson to Resetting Raffle State for the Next Round - Master the vital process of resetting your smart contract raffle state for subsequent rounds using Solidity. Learn the gas-efficient way to clear player arrays and update necessary state variables like timestamps and raffle status. Duration: 2min
13. Important: Note on learning by building
An insightful explanation of Understanding the Real Smart Contract Development Workflow - Contrast the linear tutorial approach with the actual iterative process of building smart contracts. Understand the cycle of coding, testing, debugging, and refining that defines real-world development. Duration: 2min
14. The CEI method - Checks, Effects, Interactions
An essential guide to Secure Smart Contract Development: The Checks, Effects, Interactions (CEI) Pattern - Understand the critical Checks, Effects, Interactions (CEI) pattern for secure Solidity development. Learn how structuring function logic in this specific order prevents reentrancy attacks and optimizes gas usage. Duration: 4min
15. Introduction to Chainlink Automation
A practical lesson on Automating Your Smart Contracts with Chainlink Automation - Solve the challenge of self-executing contracts using Chainlink's decentralized automation service. Compare implementing the `AutomationCompatibleInterface` for custom logic vs. the simpler UI setup for time-scheduled function calls. Duration: 17min
16. Implementing Chainlink Automation
A comprehensive introduction to Automating Your Smart Contract with Chainlink Automation - Understand how to trigger smart contract logic reliably using Chainlink Automation's `checkUpkeep` and `performUpkeep`. Follow a lottery example to implement condition checks and automated execution. Duration: 12min
17. Custom Error
A practical guide to Enhancing Solidity Error Reporting with Custom Error Parameters - Learn why generic reverts fail and how to define custom Solidity errors with parameters for better debugging. See how to pass crucial state variables like balance, player count, and contract state when reverting. Duration: 2min
18. Mid section recap
A comprehensive review of Building a Smart Contract Lottery: Code Recap and Core Concepts - Review the Raffle.sol contract's structure, core functions, and inheritance for a smart contract lottery. Understand how Chainlink VRF provides provable randomness and Automation triggers draws automatically. Duration: 3min
19. Test and deploy the lottery smart contract pt.1
A crucial overview of Introduction to Smart Contract Testing - Understand why rigorous testing is paramount for immutable smart contracts due to financial risks. Learn a strategy using Foundry deployment scripts first to ensure consistent testing across local, testnet, and mainnet forks. Duration: 2min
20. Deploy Script
An essential guide to Introduction to Foundry Deployment Scripts - Learn to structure Foundry deployment scripts using the forge-std/Script.sol contract. Implement the HelperConfig pattern for managing network-specific parameters, enabling flexible deployment across different blockchains like Sepolia and local networks. Duration: 11min
21. Deploy a mock Chainlink VRF
A practical guide to Deploying Mock Contracts for Local Development - Learn how to use `HelperConfig.sol` and Foundry cheatcodes to automatically deploy mock Chainlink contracts like VRFCoordinatorV2_5Mock. This enables reliable testing of external contract interactions in your local development environment. Duration: 7min
22. Test and deploy the lottery smart contract pt.2
A practical guide to Finalizing a Dynamic Foundry Deployment Script - Learn how to complete a robust deployment script using a `HelperConfig` contract to manage network-specific parameters. This lesson shows how to deploy your Raffle contract dynamically across local and public networks. Duration: 4min
23. Setup the tests
A step-by-step introduction to Setting Up Your First Foundry Test for a Smart Contract - Learn to structure your test environment, create test files, and write boilerplate using Foundry. Implement the `setUp` function and write/run a basic test with assertions for your smart contract. Duration: 8min
24. Headers
A fun little tool to generate Solidity headers - This video teaches you how to use a tool called 'headers' that will help generate Solidity code headers. Duration: 1min
25. Adding more tests
A foundational guide to Writing Your First Foundry Tests: The Raffle Contract - Learn to test `enterRaffle` failure (reverts) and success (state changes) using `vm.expectRevert` and `vm.prank`. Discover how to fund test accounts with `vm.deal` and debug failing tests effectively. Duration: 7min
26. Testing events
A practical tutorial on Testing Solidity Events in Foundry - Master Foundry's unique three-step workflow using `vm.expectEmit` to verify event emissions. Learn why manual event emission and definition copying are key to reliable smart contract testing. Duration: 5min
27. Using vm.roll and vm.warp
A focused guide to Testing State Transitions with Foundry: Using `vm.warp` and `vm.roll` - Discover how to use `vm.warp` and `vm.roll` cheatcodes to manipulate time and blocks in Foundry tests. Verify correct state transitions and ensure specific revert conditions, like preventing actions in invalid states, are met. Duration: 6min
28. Subscribing to events
A practical lesson on Debugging and Fixing VRF InvalidConsumer Errors in Foundry - Trace and understand the `InvalidConsumer` error when integrating Chainlink VRF in Foundry. Implement programmatic VRF subscription creation in deployment scripts to fix failing tests locally. Duration: 18min
29. Creating the subscription UI
A visual guide to Creating a VRF Subscription via the UI - Learn the manual process of creating a Chainlink VRF subscription using the web interface on the Sepolia testnet. Understand how to get testnet LINK, add it to MetaMask, and preview the UI funding mechanism. Duration: 4min
30. Fund subscription
An essential lesson on Funding Your Chainlink VRF Subscription Using a Foundry Script - Automate LINK funding for your Chainlink VRF subscription with a dedicated Foundry script. Discover how to handle mock environments versus live networks using HelperConfig and the correct token transfer mechanisms. Duration: 15min
31. Adding a consumer
A technical deep-dive into Resolving the Chainlink VRF InvalidConsumer Error in Foundry Tests - Understand the root cause of the Chainlink VRF `InvalidConsumer` error in Foundry tests. Implement an automated solution using Foundry scripting to add consumers during deployment or test setup. Duration: 13min
32. Even More Tests
A focused guide to Improving Raffle.sol Test Coverage: Targeting checkUpkeep - Learn to write targeted unit tests for the `checkUpkeep` function using the AAA pattern and Foundry cheatcodes. Enhance confidence by testing scenarios where upkeep should not be triggered, like zero balance or incorrect state. Duration: 5min
33. Coverage Report
A practical lesson on Pinpointing Untested Code with Foundry's Debug Coverage Report - Go beyond basic coverage metrics by using Foundry's detailed debug report. Learn to generate, save, and interpret this report to pinpoint and address untested lines and branches in your Solidity code. Duration: 4min
34. Testing and refactoring the performUpkeep
A practical tutorial on Testing the `performUpkeep` Function - Learn how to write Foundry unit tests for the conditional logic between `checkUpkeep` and `performUpkeep`. Verify successful execution and test for specific custom error reverts using cheatcodes. Duration: 7min
35. Refactoring events data
A hands-on tutorial to Capturing Solidity Events in Foundry Tests - Master Foundry cheatcodes like `vm.recordLogs` and `vm.getRecordedLogs` to verify event emissions from your smart contracts. Learn to decode event parameters from `Vm.Log` and use modifiers for efficient test setup. Duration: 9min
36. Intro to fuzz testing
A practical lesson on Introduction to Stateless Fuzz Testing in Foundry - Move beyond hardcoded test inputs and discover Foundry's stateless fuzzing capabilities. See how to automatically test function preconditions with random data to uncover hidden edge cases and enhance contract robustness. Duration: 9min
37. One Big Test
An in-depth guide to Crafting Comprehensive End-to-End Unit Tests in Foundry for Smart Contracts - Learn to build a full lifecycle test for a raffle contract using Foundry, simulating Chainlink VRF callbacks. Master Arrange-Act-Assert, cheatcodes like `hoax` and `recordLogs`, mock contracts, and debugging for robust E2E validation. Duration: 13min
38. Forked test environment and dynamic private keys
A troubleshooting guide to Bridging the Gap: From Local Success to Forked Test Failures - Resolve discrepancies between local and forked Foundry tests by managing account permissions correctly. Learn to use specific senders and selectively skip tests for reliable cross-environment validation. Duration: 12min
39. Creating integration tests
A practical guide to Integrating the Pieces: Moving Beyond Unit Tests with Foundry - Move beyond unit tests by learning how integration tests verify the interaction between deployment scripts, contracts, and interaction scripts in Foundry. Explore the testing spectrum and the goal of increasing script coverage. Duration: 4min
40. Deploy the lottery on the testnet pt.1
A comprehensive guide to Deploying Your Smart Contract Lottery to Sepolia Testnet - This lesson walks through deploying a Solidity lottery contract to the Sepolia testnet using Forge and a Makefile. Learn to integrate Chainlink VRF and Automation, verify contracts on Etherscan, and observe the automated raffle process. Duration: 16min
41. Implementing console log in your smart contract
A valuable tutorial on Debugging Solidity with In-Contract Console Logging - Master in-contract debugging using `console.log` from `forge-std` in your Foundry projects. This lesson covers implementation, viewing logs with verbose test flags, and the gas implications for production code. Duration: 1min
42. Debug using forge test
An insightful introduction to Diving Deep: Introduction to the Foundry Opcode Debugger - Delve into the EVM's low-level operations by stepping through individual opcodes with Foundry's debugger. Learn how this advanced tool aids in precision analysis, gas optimization, and security auditing. Duration: 1min
43. Section recap
A comprehensive review of Building a Provably Fair Decentralized Lottery - Revisit the key components like the `Raffle.sol` contract, Chainlink VRF/Automation integration, and the CEI security pattern. Understand how Foundry deployment scripts and thorough testing create a robust, verifiable dApp. Duration: 6min

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 April 5, 2025

Testimonials

Students Reviews

Read what our students have to say about this course.

Chainlink

Chainlink

Chainlink

Gustavo Gonzalez

Gustavo Gonzalez

Solutions Engineer at OpenZeppelin

Francesco Andreoli

Francesco Andreoli

Lead Devrel at Metamask

Albert Hu

Albert Hu

DeForm Founding Engineer

Radek

Radek

Senior Developer Advocate at Ceramic

Boidushya

Boidushya

WalletConnect

Idris

Idris

Developer Relations Engineer at Axelar

Cyfrin
Updraft
CodeHawks
Solodit
Resources