Skip to content

thebraveman17/Foundry

 
 

Repository files navigation

Entire course and video content updated June 15, 2024

Blockchain Developer, Smart Contract, & Solidity Career Path - Powered By AI - Beginner to Expert Course
| Foundry Edition 2024 |

Learn smart contract development, and level up your career

Stargazers Forks Contributors Issues MIT License



Welcome to the repository for the Blockchain Developer, Smart Contract, & Solidity Cyfrin Updraft - Career Path
| Powered By AI |
| Beginner to Expert Path |
| Foundry Edition 2024 |

This repository houses course resources and discussions for the course.

Please refer to this for an in-depth explanation of the content:

  • Website - Join Cyfrin Updraft and enjoy 50+ hours of smart contract development courses
  • Twitter - Stay updated with the latest course releases
  • LinkedIn - Add Updraft to your learning experiences
  • Discord - Join a community of 3000+ developers and auditors
  • Newsletter - Weekly security research tips and resources to level up your career
  • Codehawks - Smart contracts auditing competitions to help secure web3

Blockchain Developer, Smart Contract, & Solidity Course - Powered By AI


Cyfrin Updraft Courses:

YouTube Link

Table of Contents

All the sections for on this repo are for several courses on the Solidity Developer Career path of Cyfrin Updraft.

Resources
  1. Blockchain Developer, Smart Contract, & Solidity Course - Powered By AI - Beginner to Expert Course | Foundry Edition 2024
  2. Table of Contents
  3. Testnet Faucets
  4. Resources For This Course
  5. Bonus NFTs
Welcome to the Course Repo!
  1. Welcome to the course!
  2. Best Practices
Course: Blockchain Basics Section 1
  1. What is a Blockchain? What does a blockchain do?
  2. The Purpose Of Smart Contracts
  3. Other Blockchain Benefits
  4. What have Smart Contracts done so far?
  5. Making Your First Transaction
  6. Gas I: Introduction to Gas
  7. How Do Blockchains Work?
  8. Signing Transactions
  9. Gas II
  10. Gas II Summary
  11. High-Level Blockchain Fundamentals
  12. L1s L2s and Rollups
  13. Rollup Stages
  14. Making your First Transaction on zkSync
  15. Why zkSync is our Recommended Chain
Solidity 101 Section 1: Simple Storage
  1. Introduction
  2. Setting Up Your First Contract
  3. Basic Solidity: Types
  4. Basic Solidity: Functions
  5. Basic Solidity: Arrays & Structs
  6. Basic Solidity: Compiler Errors and Warnings
  7. Memory, Storage, Calldata (Intro)
  8. Mappings
  9. Deploying your First Contract
  10. The EVM & A Recap of Section 2
Solidity 101 Section 2: Remix Storage Factory
  1. Introduction
  2. Basic Solidity: Importing Contracts into other Contracts
  3. Basic Solidity: Interacting with other Contracts
  4. Basic Solidity: Inheritance & Overrides
  5. Section 3 Recap
Solidity 101 Section 3: Remix Fund Me
  1. Introduction
  2. Setup
  3. Sending ETH through a function
  4. Reverts
  5. Getting real world price data (Chainlink)
  6. Quick recap I
  7. Interfaces
  8. AI Help III
  9. Importing from NPM / GitHub
  10. Getting Prices from Chainlink
  11. More solidity math
  12. msg.sender
  13. Quick recap II
  14. Library
  15. SafeMath
  16. For Loop
  17. Resetting an array
  18. Transfer, Send, and Call
  19. Constructor
  20. Modifiers
  21. Testnet Demo
  22. Advanced Solidity
  23. Section 4 Recap
Solidity 101 Section 4: AI Prompting, Asking Questions, and Getting Help
  1. Intro
  2. 7 Tips for this Course
  3. Setting up GitHub
  4. Formatting a question
  5. SpeedRunEthereum
Foundry Fundamentals Section 1: Foundry Simple Storage
  1. Introduction
  2. Installation & Setup (MacOS & Linux)
  3. Local Development Introduction
  4. Foundry Install
  5. VSCode Setup II
  6. Foundry Setup
  7. Formatting Solidity in VSCode
  8. Compiling in Foundry
  9. Deploying to a local chain I (Anvil or Ganache)
  10. Adding another network to metamask
  11. Deploying to a local chain II (Forge Create)
  12. Private Key Rant I
  13. Deploying to a local chain III (Forge Script)
  14. What is a transaction (But actually)
  15. Private Key Rant II
  16. Can you Encrypt a Private Key -> a keystore in foundry yet??
  17. ThirdWeb Deploy
  18. Private Key Rant Summary:
  19. Cast Send
  20. Deploying to a testnet or a mainnet
  21. Verifying a contract the manual way
  22. Cleaning up the project
  23. Alchemy and the mempool
  24. Summary
Foundry Fundamentals Section 2: Foundry Fund Me
  1. Introduction
  2. Setup
  3. Testing Introduction
  4. Setup Continued
  5. Tests
  6. Debugging Tests I
  7. Advanced Deploy Scripts I
  8. Forked Tests
  9. Refactoring I: Testing Deploy Scripts
  10. Refactoring II: Helper Config
  11. Refactoring III: Mocking (continued)
  12. Magic Numbers
  13. Break time!
  14. More Cheatcodes
  15. More Coverage
  16. Chisel
  17. Gas: Cheaper Withdraw
  18. Storage
  19. Gas: Cheaper Withdraw (continued)
  20. Interactions.s.sol
  21. Makefile
  22. Pushing to GitHub
  23. Recap
Foundry Fundamentals Section 3: Html/Js Fund Me (Quick Fullstack / Front End Tutorial)
  1. Introduction
  2. Setup
  3. How metamask works with your browser
  4. Introduction to function selectors
  5. Recap
Foundry Fundamentals Section 4: Foundry Smart Contract Lottery
  1. Introduction
  2. Raffle.sol Setup
  3. Solidity Contract Layout
  4. Custom Errors
  5. Events
  6. block.timestamp
  7. Chainlink VRF
  8. Implementing Chainlink VRF - Introduction
  9. Modulo
  10. Enum
  11. Resetting an array
  12. Note on building
  13. CEI
  14. Introduction to Chainlink Automation
  15. Implementing Chainlink Keepers - checkUpkeep
  16. Implementing Chainlink Keepers - checkUpkeep continued
  17. Implementing Chainlink Keepers - performUpkeep
  18. Mid-Section Recap
  19. Tests & Deploy Script Setup
  20. Tests & Deploy Script Continued
  21. Lots of Tests
  22. Create Subscription Script
  23. Create Subscription from the UI
  24. Fund Subscription Script
  25. Add Consumer Script
  26. More Tests
  27. PerformUpkeep Tests
  28. Getting Event Data into Foundry Scripts
  29. Intro to Fuzz tests
  30. One Big Test
  31. Passing the private key to vm.startBroadcast
  32. Integrations Test
  33. Testnet Demo - Makefile setup
  34. Testnet Demo - The Demo
  35. Console.log Debugging
  36. forge test --debug
  37. Recap
Advanced Foundry Section 1: Foundry ERC20s
  1. What is an ERC? What is an EIP?
  2. What is an ERC20?
  3. Manually Creating an ERC20 Token
  4. ERC20 Token - Openzeppelin
  5. Deploy Script
  6. AI Tests
  7. Section 10 Recap
Advanced Foundry Section 2: Foundry NFTs | MoodNFT
  1. Introduction
  2. What is an NFT?
  3. Foundry Setup
  4. IPFS
  5. Using IPFS
  6. Basic NFT: Deploy Script
  7. Basic NFT: Tests
  8. Basic NFT: Interactions
  9. Basic NFT: Testnet Demo
  10. The issue with IPFS & HTTPS TokenURI NFTs
  11. What is an SVG?
  12. SVG NFT: Introduction
  13. SVG NFT: Encoding the NFT
  14. SVG NFT: Flipping the mood
  15. SVG NFT: Deploy Script
  16. SVG NFT: Debugging practice & some notes
  17. SVG NFT: Anvil Demo
  18. Advanced: EVM Opcodes, Encoding, and Calling
  19. Verifying Metamask Transactions
  20. Filecoin & Arweave
  21. Section 11 Recap
Advanced Foundry Section 3: Foundry DeFi | Stablecoin (The PINNACLE PROJECT!! GET HERE!)
  1. What is DeFi?
  2. Code Walkthrough
  3. What is a stablecoin (But actually)
  4. DecentralizedStableCoin.sol
  5. DSCEngine.sol Setup
  6. Deposit Collateral
  7. Mint DSC
  8. Testing while developing
  9. depositCollateralAndMintDsc
  10. redeemCollateral
  11. Liquidate
  12. Leveling up your testing skillz
  13. Fuzz (Invariant) Testing
  14. Open-based Fuzz tests
  15. Handler-based Fuzz tests
  16. Price Feed Handling
  17. OracleLib
  18. Note on audit preparedness
  19. Recap
  20. Lens Protocol
Advanced Foundry Section 4: Foundry Merkle Airdrop and Signatures
  1. Introduction to Merkle Airdrops and Code Walkthrough
  2. Project Setup
  3. Merkle Proofs
  4. Base Airdrop Contract
  5. Already Claimed Check
  6. Merkle Tree Scripts
  7. Writing the Tests
  8. Deployment Script
  9. Adding Signature Verification
  10. Signature Standards
  11. ECDSA Signatures
  12. Transaction Types Introduction
  13. Transaction Types
  14. Blob Transactions
  15. Type 113 Transactions
  16. Implementing Signatures
  17. Modifying the Tests
  18. Test on zkSync (optional)
  19. Create Claiming Script
  20. Creating a Signature
  21. Splitting a Signature
  22. Executing the Anvil Script
  23. Deploy and Claim on zkSync Local Node
  24. Deploy and Claim on zkSync Sepolia
  25. Summary
Advanced Foundry Section 5: Foundry Upgrades
  1. Introduction
  2. Upgradable Smart Contracts Overview
  3. Types of Upgrades
  4. Delegatecall
  5. Small Proxy Example
  6. Universal Upgradable Smart Contract
  7. Testnet Demo
Advanced Foundry Section 6: Foundry Account Abstraction
Advanced Foundry Section 7: Foundry DAO / Governance
  1. Introduction
  2. What is a DAO?
  3. How to build a DAO
  4. Wrap up
  5. Bonus: Gas optimization tips
Advanced Foundry Section 8: Smart Contract Security & Auditing (For developers)
  1. Introduction
  2. What is a smart contract audit?
  3. Tools
  4. What does the process of manual review look like?
  5. Formal Verification
  6. Closing Thoughts
Congratulations
  1. Where do I go now?

Disclosures

Thank you

Recommended Tools

⚠️ All code associated with this course is for demo purposes only. They have not been audited and should not be considered production ready. Please use at your own risk.

Chainlist

Resources For This Course

Bonus NFTs

These are 100% optional to do.

After every section, in this GitHub repo will be a link to a contract on Sepolia or zkSync. They contain a challenge for you to solve, and in return, you'll be given an AWESOME NFT.

Important Notes for zkSync

IF YOU DECIDE TO MINT THE REAL NFT:

  1. We didn't audit the NFT, so if you want to make sure you'll be safe, interact with the contract using a burner wallet (a wallet with very little money that you don't use for anything else)
    1. In fact... Get good at interacting with wallets from a burner wallet
  2. Read my Tweet thread on basic wallet safety
  3. It might be a good idea to wait till later in the course when we teach you about verifying metamask transactions.
  4. Feel free to mint NFTs on sepolia without worrying about the above

Bridging to zkSync

  1. The process for bridging looks like the following:
    1. Buy ETH (On an exchange like Coinbase or Kraken)
  2. Send ETH -> one of your wallets like:
    1. Metamask
    2. Frame
    3. Rainbow
    4. Argent
    5. Coinbase Wallet
  3. Use the zkSync Bridge

Welcome to the Course Repo

Welcome to Ultimate Smart Contract Development Course!

Best Practices

  • Follow the repository: While going through the course be 100% certain to follow along with the github repository. If you run into an issue check the chronological-updates in the repo.
  • Be Active in the community: Ask questions and engage with other developers going through the course in the discussions tab, be sure to go and say hello or gm! This space is different from the other industries, you don't have to be secretive; communicate, network and learn with others :)
  • Learn at your own pace: It doesn't matter if it takes you a day, a week, a month or even a year. Progress >>> Perfection
  • Take Breaks: You will exhaust your mind and recall less if you go all out and watch the entire course in one sitting. Suggested Strategy every 25 minutes take a 5 min break, and every 2 hours take a longer 30 min break
  • Refer to Documentation: Things are constantly being updated, so whenever Patrick opens up some documentation, open it on your end and maybe even have the code sample next to you.
  • Use ChatGPT and/or the course chat

(back to top) ⬆️

Course: Blockchain Basics

⭐️ Blockchain Basics Course

Blockchain Basics Section 1: What is a Blockchain? What does a blockchain do?

⌨️ What is a Blockchain?

The Purpose Of Smart Contracts

⌨️ The Purpose Of Smart Contracts

Other Blockchain Benefits

⌨️ Other Blockchain Benefits

  • Decentralized
  • Transparency & Flexibility
  • Speed & Efficiency
  • Security & Immutability
  • Counterparty Risk Removal
  • Trust Minimized Agreements

What have Smart Contracts done so far?

Making Your First Transaction

⌨️ Making Your First Transaction

Gas I: Introduction to Gas

⌨️ Gas I: Introduction to Gas

How Do Blockchains Work?

⌨️ How Do Blockchains Work?

Signing Transactions

⌨️ Signing Transactions

Gas II

⌨️ Gas II: Block Rewards & EIP 1559

Gas II Summary

High-Level Blockchain Fundamentals

⌨️ High-Level Blockchain Fundamentals

L1s L2s and Rollups

Rollup Stages

Making your First Transaction on zkSync

Why zkSync is our Recommended Chain

Blockchain Basics Section 1 NFTs

(back to top) ⬆️

Course: Solidity & Smart Contract Developmnet

⭐️ Learn Solidity & Smart Contract Development

💻 Code: https://github.com/cyfrin/remix-simple-storage-cu

Solidity 101 Section 1: Simple Storage

Introduction

⭐️ Welcome to Remix - Simple Storage

Setting Up Your First Contract

⌨️ Setting Up Your First Contract

Basic Solidity: Types

⌨️ Basic Solidity Types

Basic Solidity: Functions

⌨️ Basic Solidity Functions

  • Functions
  • Deploying a Contract
    • Smart Contracts have addresses just like our wallets
  • Calling a public state-changing Function
  • Visibility
  • Gas III | An example
  • Scope
  • View & Pure Functions

Basic Solidity: Arrays & Structs

⌨️ Basic Solidity Arrays & Structs

  • Structs
  • Intro to Storage
  • Arrays
  • Dynamic & Fixed Sized
  • push array function

Basic Solidity: Compiler Errors and Warnings

⌨️ Basic Solidity Errors & Warnings

  • Yellow: Warnings are Ok
  • Red: Errors are not Ok

Memory, Storage, Calldata (Intro)

⌨️ Basic Solidity Memory, Storage, & Calldata (Intro)

  • 6 Places you can store and access data
    • calldata
    • memory
    • storage
    • code
    • logs
    • stack

Mappings

⌨️ Basic Solidity Mappings

Deploying your First Contract

⌨️ Deploying your First Contract

  • A testnet or mainnet
  • Connecting Metamask
  • Find faucets here!
  • See the faucets at the top of this readme!
  • Interacting with Deployed Contracts

zkSync L2 deploy

⌨️ Deploying to Zksync

  • zkSync compiler edition: 0.8.24

The EVM & A Recap of the section

⌨️ The EVM & A Recap of Section 2

  • The EVM

Solidity 101 Section 1 NFTs

(back to top) ⬆️

Solidity 101 Section 2 | Remix Storage Factory

💻 Code: https://github.com/cyfrin/remix-storage-factory-cu

Introduction

⭐️ Section 2 | Storage Factory

Basic Solidity: Importing Contracts into other Contracts

⌨️ Importing Contracts into other Contracts

Basic Solidity: Interacting with other Contracts

⌨️ Interacting with other contracts

  • To interact, you always need: ABI + Address
  • ABI

Basic Solidity: Inheritance & Overrides

⌨️ Inheritance & Overrides

Section 2 Recap

⌨️ Section 2 Recap

Solidity 101 Section 2 NFTs

(back to top) ⬆️

Solidity 101 Section 3: Remix Fund Me

💻 Code: https://github.com/Cyfrin/remix-fund-me-cu

Introduction

⭐️ Section 3 | Fund Me

Setup

⌨️ Setup

Sending ETH through a function

⌨️ Sending ETH through a function

Reverts

⌨️ Reverts

Getting real world price data (Chainlink)

⌨️ Getting real world price data (Chainlink)

Quick recap I

⌨️ Quick recap I

Interfaces

⌨️ Interfaces

AI Help III

⌨️ AI Help III

Importing from NPM / GitHub

⌨️ Importing from NPM / GitHub

Getting Prices from Chainlink

⌨️ Getting Prices from Chainlink

More Solidity math

⌨️ More Solidity math

msg.sender

⌨️ msg.sender

Quick recap II

⌨️ Quick recap II

Library

⌨️ Library

SafeMath

⌨️ SafeMath

For Loop

⌨️ For Loop

  • For Loop
  • /* */ is another way to make comments

Resetting an array

⌨️ (Resetting an array

Transfer, Send, and Call

⌨️ Transfer, Send, and Call

Constructor

⌨️ Constructor

Modifiers

⌨️ Modifiers

Testnet Demo

⌨️ Tesnet Demo

Immutable & Constant

⌨️ Immutable & Constant

Custom Errors

⌨️ Custom Errors

Receive & Fallback Functions

⌨️ Receive & Fallback Functions

Section 3 Recap

⌨️ Section 3 Recap

Solidity 101 Section 3 NFTs

(back to top) ⬆️

Solidity 101 Section 4: AI Prompting, Asking Questions, and Getting Help

DO NOT SKIP THIS!!

⭐️ Section 4 | AI Prompting

Intro

7 Tips for this Course

Setting up GitHub

⌨️ Setting up GitHub

Formatting a question

⌨️ Formatting a question

  • It's a good idea to ask your AI buddy to format your questions in markdown *

SpeedRunEthereum

⌨️ SpeedRunEthereum

Solidity 101 Section 4 NFTs

(back to top) ⬆️

Course: Foundry Fundamentals

Foundry Fundamentals Section 1: Foundry Simple Storage

💻 Code: https://github.com/Cyfrin/foundry-simple-storage-cu

Introduction

⭐️ Foundry Simple Storage Introduction

Installation & Setup (MacOS & Linux)

⌨️ Installation & Setup (MacOS & Linux)

Windows Setup (WSL)

⌨️ (Windows Setup (WSL)

  • Special Guest Vasiliy
  • WSL
    • When working in WSL, use Linux commands instead of Windows commands
  • TroubleShooting
  • curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

⚠️ Please use Gitpod as an absolute last resort

Gitpod

⌨️ Gitpod

  • Gitpod
    • If using this, NEVER share a private key with real money on Gitpod
    • Ideally you figure out the MacOS, Linux, or Windows install though

Local Development Introduction

  • CMD + K or CTRL + K clears the terminal
  • code . to open VSCode in a new VSCode window

Foundry Install

⌨️ Foundry Install

VSCode Setup II

⌨️ VSCode Setup II

  • CoPilot
  • Copilot labs
  • Hardhat Solidity Extension
  • VSCodium
  • mkdir foundry-cu
  • cd foundry-cu
  • mkdir foundry-simple-storage-cu

Foundry Setup

⌨️ Foundry Setup ⌨️ Foundry Setup II (WSL)

  • FreeCodeCamp Bash

Formatting Solidity in VSCode

⌨️ Formatting Solidity in VSCode

  • Format your solidity code within your settings.json
    "[solidity]": {
        "editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
    },
    "[javascript]":{
      "editor.defaultFormatter": "esbenp.prettier-vscode"
    }

Compiling in Foundry

⌨️ Compiling in Foundry

Compiling to zkSync in foundry-zksync

Deploying to a local chain I (Anvil or Ganache)

⌨️ Deploying to a local chain I (Anvil or Ganache)

Adding another network to Metamask

⌨️ Adding another network to Metamask

Deploying to a local chain II (Forge Create)

⌨️ Deploying to a local chain II (Forge Create)

  • 2 Ways to deploy:
      1. forge create
      1. forge script

Private Key Rant I

⌨️ Private Key Rant I

  • history -c

Deploying to a local chain III (Forge Script)

⌨️ Deploying to a local chain III (Forge Script)

What is a transaction (But actually)

⌨️ What is a transaction (But actually)

cast --to-base 0x01 dec

Private Key Rant II

⌨️ Private Key Rant II

  • cast send
  • source .env

Can you Encrypt a Private Key -> a keystore in foundry yet??

Can you Encrypt a Private Key -> a keystore in foundry yet??

  • A: No Yes, try the new feature by
cast wallet import your-account-name --interactive
Enter private key:
Enter password:
`your-account-name` keystore was saved successfully. Address: address-corresponding-to-private-key
forge script <script> --rpc-url <rpc_url> --account <account_name> --sender <address> --broadcast

Never use a Env File

⌨️ Never use a Env File

Private Key Rant Summary:

Private Key Rant Summary

Summary:
When you look to deploy
with real money, you should use either:
1. A password encrypted keystore
2. Something like thirdweb deploy

The idea is you never want to have
your private key or password
ANYWHERE written in plain text
(Aka, you always want it encrypted)

Deploying to a testnet or a mainnet

⌨️ Deploying to a testnet Sepolia

Verifying a contract the manual way

⌨️ Verifying a contract the manual way

Cleaning up the project

⌨️ Cleaning up the project

  • forge fmt
  • README.md

Foundry Zksync

Alchemy and the mempool

⌨️ Alchemy and the mempool

Summary

⌨️ Summary

Foundry Fundamentals Section 1 NFTs

(back to top) ⬆️

Foundry Fundamentals Section 2: Foundry Fund Me

⭐️ Foundry Fund Me

💻 Code: https://github.com/Cyfrin/foundry-fund-me-cu

Introduction

⌨️ Introduction

Setup

⌨️ Setup

Testing Introduction

⌨️ Testing Introduction

Setup Continued

⌨️ Setup Continued

Tests

⌨️ Tests

Debugging Tests I

⌨️ Debugging Tests I

Advanced Deploy Scripts I

⌨️ Advanced Deploy Scripts I

Forked Tests

⌨️ Forked Tests

  • The test option -m regex is deprecated. Please use --match-test or --mt instead.
forge test -m testPriceFeedVersionIsAccurate -vvv

is deprecated. Please use

forge test --match-test testPriceFeedVersionIsAccurate -vvv
  • 4 types of testing:
1. Unit: Testing a single function
2. Integration: Testing multiple functions
3. Forked: Testing on a forked network
4. Staging: Testing on a live network (testnet or mainnet)

Refactoring I: Testing Deploy Scripts

⌨️ Refactoring I: Testing Deploy Scripts

Refactoring II: Helper Config

⌨️ Refactoring II: Helper Config

Refactoring III: Mocking

⌨️ Refactoring III: Mocking

Magic Numbers

⌨️ Magic Numbers

Refactoring III: Mocking (continued)

⌨️ Refactoring III: Mocking (continued)

More Cheatcodes

⌨️ More Cheatcodes

More Coverage

⌨️ More Coverage

Chisel

⌨️ Chisel

Gas: Cheaper Withdraw

⌨️ Gas: Cheaper Withdraw

  • Gas Reporter
  • forge snapshot
  • vm.txGasPrice
  • gasLeft()
  • tx.getprice

Storage

⌨️ Storage

cast storage

Gas: Cheaper Withdraw (continued)

⌨️ Gas: Cheaper Withdraw (continued)

Interactions.s.sol

⌨️ Interactions.s.sol

Makefile

⌨️ Makefile

Zksync Devops

⌨️ Zksync Devops

Pushing to GitHub

⌨️ Pushing to GitHub

⌨️ (2:34:56) | Tweet Me (add your repo in)!

Section 2: Recap

⌨️ Section 2: Recap

Foundry Fundamentals Section 2 NFTs

(back to top) ⬆️

Foundry Fundamentals Section 3: Html/Js Fund Me (Quick Fullstack / Front End Tutorial)

⭐️ Section 3: HTML Fund Me

💻 Code: https://github.com/Cyfrin/html-fund-me-cu

Introduction

Setup

⌨️ Setup

How Metamask works with your browser

⌨️ How Metamask works with your browser

Introduction to function selectors

⌨️ Introduction to function selectors

Recap

⌨️ Recap

Foundry Fundamentals Section 3 NFTs

  • IPFS hash for website - ipfs://QmdCBj5B188qzXgG1LUCD6aKe6RJHqbSgu7YfPyncDirzh

(back to top) ⬆️

Foundry Fundamentals Section 4: Foundry Smart Contract Lottery

⭐️ Section 4: Smart Contract Lottery

💻 Code: https://github.com/Cyfrin/foundry-smart-contract-lottery-cu

Introduction

⌨️ Introduction

Raffle.sol Setup

⌨️ Raffle.sol Setup

  • Raffle.sol Setup

Solidity Contract Layout

⌨️ Solidity Contract Layout

// Layout of Contract:
// version
// imports
// errors
// interfaces, libraries, contracts
// Type declarations
// State variables
// Events
// Modifiers
// Functions

// Layout of Functions:
// constructor
// receive function (if exists)
// fallback function (if exists)
// external
// public
// internal
// private
// internal & private view & pure functions
// external & public view & pure functions

Custom Errors

⌨️ Custom Errors

  • Custom Errors in Solidity

Events

⌨️ Events

  • Introduction to Events
  • Events & Logging Video
  • Events & Logging in Hardhat

block.timestamp

⌨️ block.timestamp

Chainlink VRF

⌨️ Chainlink VRF

  • Introduction to Chainlink VRF

Sub-Section: Chainlink VRF

  • Chainlink VRFv2 Docs
  • Chainlink VRFv2 Walkthrough
  • Chainlink Contracts

Implementing Chainlink VRF - Introduction

⌨️ Implementing Chainlink VRF - Introduction

  • Implementing Chainlink VRF
forge install smartcontractkit/chainlink-brownie-contracts@0.6.1 --no-commit

Modulo

⌨️ Modulo

  • Modulo

Enum

⌨️ Enum

Resetting an array

⌨️ Resetting an array

Note on building

⌨️ Note on building

CEI (Checks, Effects, Interactions)

⌨️ CEI (Checks, Effects, Interactions)

Introduction to Chainlink Automation

⌨️ Introduction to Chainlink Automation

  • Chainlink Automation Docs
  • Chainlink Automation Walkthrough

Implementing Chainlink Keepers - checkUpkeep

⌨️ Implementing Chainlink Keepers - checkUpkeep

Enums

  • Enum

Implementing Chainlink Keepers - checkUpkeep continued

  • block.timestamp

Custom Error

⌨️ Custom Error

Mid-Section Recap

⌨️ Mid-Section Recap

Tests & Deploy Script Setup

⌨️ Tests & Deploy Script Setup

Deploy Script

⌨️ Script Setup

Mock Chainlink VRF Coordinator

⌨️ Mock Chainlink VRF Coordinator

Tests & Deploy Script Continued

⌨️ Tests & Deploy Script Continued

Lots of Tests

⌨️ Lots of Tests

Headers

⌨️ Headers

Adding more tests.

⌨️ Adding more tests

Testing Events in Foundry

⌨️ Testing Events in Foundry

vm.roll & vm.warp

⌨️ vm.roll & vm.warp

Create Subscription Script

⌨️ Create Subscription Script

Create Subscription from the UI

⌨️ Create Subscription from the UI

Fund Subscription Script

⌨️ Fund Subscription Script

Add Consumer Script

⌨️ Add Consumer Script

More Tests

⌨️ More Tests

  • forge coverage --report debug

Coverage Report

⌨️ Coverage Report

PerformUpkeep Tests

⌨️ PerformUpkeep Tests

  • Expecting Custom Errors

Getting Event Data into Foundry Scripts

⌨️ Getting Event Data into Foundry Scripts

  • vm.recordLogs

Intro to Fuzz tests

⌨️ Intro to Fuzz tests

One Big Test

⌨️ One Big Test

Passing the private key to vm.startBroadcast

⌨️ Passing the private key to vm.startBroadcast

Integrations Test

⌨️ Integrations Test

Testnet Demo - Optional

⌨️ Testnet Demo - Optional

Console.log Debugging

⌨️ Console.log Debugging

forge test --debug

⌨️ forge test --debug

Recap

⌨️ Recap

Recommended LINK amounts for Sepolia Staging Test:

  • Chainlink VRF: 2 LINK
  • Chainlink Keepers: 8 LINK

Foundry Fundamentals Section 4 NFTs

(back to top) ⬆️

🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊

Completed Foundry Fundamentals

🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊


Course: Advanced Foundry

Advanced Foundry Section 1: Foundry ERC20s

⭐️ Section 1: ERC20s

💻 Code: https://github.com/Cyfrin/foundry-erc20-cu

What is an ERC? What is an EIP?

  • What is an EIP?
  • EIPs codebase

What is an ERC20?

⌨️ What is an ERC20?

Manually Creating an ERC20 Token

⌨️ Manually Creating an ERC20 Token

  • .github

ERC20 Token - Openzeppelin

⌨️ ERC20 Token - Openzeppelin

Deploy Script

⌨️ Deploy Script

AI Tests

⌨️ AI Tests

Advanced Foundry Section 1 NFTs

(back to top) ⬆️

Advanced Foundry Section 2: Foundry NFTs | MoodNFT

⭐️ Section 2: NFTs

💻 Code: https://github.com/Cyfrin/foundry-nft-cu

Introduction

What is an NFT?

⌨️ What is an NFT?

  • Video
  • Optional: All on Chain SVG NFT
  • EIP-721

Foundry Setup

⌨️ Foundry Setup

  • TokenURI
  • Pudgy Penguin Example

IPFS

⌨️ IPFS

Using IPFS

⌨️ Using IPFS

Basic NFT: Deploy Script

⌨️ Basic NFT: Deploy Script

Basic NFT: Tests

⌨️ Basic NFT: Tests

  • Comparing strings in solidity
  • chisel

Basic NFT: Interactions

⌨️ Basic NFT: Interactions

Basic NFT: Testnet Demo

⌨️ Basic NFT: Testnet Demo

The issue with IPFS & HTTPS TokenURI NFTs

⌨️ The issue with IPFS & HTTPS TokenURI NFTs

What is an SVG?

⌨️ What is an SVG?

SVG NFT: Introduction

⌨️ SVG NFT: Introduction

SVG NFT: Encoding the NFT

⌨️ SVG NFT: Encoding the NFT

SVG NFT: Flipping the mood

⌨️ SVG NFT: Flipping the mood

SVG NFT: Deploy Script

⌨️ SVG NFT: Deploy Script

SVG NFT: Debugging practice & some notes

⌨️ SVG NFT: Debugging practice & some notes

SVG NFT: Anvil Demo

⌨️ SVG NFT: Anvil Demo

NFTS: Filecoin & Arweave

⌨️ NFTS: Filecoin & Arweave

Advanced: EVM Opcodes, Encoding, and Calling

⌨️ Advanced: EVM Opcodes, Encoding, and Calling

abi.encode & abi.encodePacked

  • abi.encode
  • abi.encodePacked Thanks to Alex Roan for his help on this session!
  • Example Contract Creation Transaction What REALLY is the ABI?
  • EVM Opcodes
  • More EVM Opcodes
  • Solidity Cheatsheet
  • abi.encode vs abi.encodePacked

Introduction to Encoding Function Calls Directly

⌨️ Introduction to Encoding Function Calls Directly

Introduction to Encoding Function Calls Recap

⌨️ Introduction to Encoding Function Calls Recap

Encoding Function Calls Directly

⌨️ Encoding Function Calls Directly

  • Function Selector
  • Function Signature

Verifying Metamask Transactions

⌨️ Verifying Metamask Transactions

  1. Check the address
  2. Check the function selector
  3. Decode the calldata

Section 2 Recap

⌨️ (10:36:31) | Section 2 Recap

Advanced Foundry Section 2 NFTs

(back to top) ⬆️

Advanced Foundry Section 3: Foundry DeFi | Stablecoin (The PINNACLE PROJECT!! GET HERE!)

💻 Code: https://github.com/Cyfrin/foundry-defi-stablecoin-cu

Introduction

⭐️ Section 3: DeFi Stablecoins

What is DeFi?

Code Walkthrough

⌨️ Code Walkthrough

What is a stablecoin (But actually)

⌨️ What is a stablecoin (But actually)

DecentralizedStableCoin.sol

⌨️ DecentralizedStableCoin.sol

DSCEngine.sol Setup

⌨️ DSCEngine.sol Setup

Deposit Collateral

⌨️ Deposit Collateral

Mint DSC

Getting the value of our collateral

⌨️ Getting the value of our collateral

Health Factor

⌨️ Health Factor

Minting the DSC

⌨️ Minting the DSC

Testing while developing

Deploy Script

⌨️ Deploy Script

Tests

⌨️ Tests

depositCollateralAndMintDsc

⌨️ depositCollateralAndMintDsc

redeemCollateral

⌨️ redeemCollateral

Liquidate

Setup

⌨️ Setup

Refactoring

⌨️ Refactoring

Leveling up your testing skillz

⌨️ Leveling up your testing skillz

Challenge: Get DSCEngine.sol test coverage above 85%

Fuzz (Invariant) Testing

⌨️ Fuzz (Invariant) Testing

Open-based Fuzz tests

⌨️ Open-based Fuzz tests

Handler-based Fuzz tests

revert_on_fail = true

⌨️ revert_on_fail = true

Create the collateral redeemal handler

⌨️ Create the collateral redeemal handler

DeFi Handler Deposit Collateral

⌨️ DeFi Handler Deposit Collateral

Minting DSC

⌨️ Minting DSC

Debugging Fuzz Tests

⌨️ Debugging Fuzz Tests

Challenge: Find out why mintDsc is never being called on our Handler.sol

Price Feed Handling

⌨️ Price Feed Handling

OracleLib

⌨️ OracleLib

Note on audit preparedness

⌨️ Note on audit preparedness

Recap

⌨️ Recap

Lens Protocol

⌨️ Lens Protocol

More DeFi Learnings:

Advanced Foundry Section 3 NFTs

(back to top) ⬆️

Advanced Foundry Section 4: Foundry Merkle Airdrop and Signatures

💻 Code: https://github.com/Cyfrin/foundry-merkle-airdrop-cu

Introduction to Merkle Airdrops and Code Walkthrough

⌨️ Introduction

Project Setup

⌨️ Project Setup

Merkle Proofs

⌨️ Merkle Proofs

Base Airdrop Contract

⌨️ Base Airdrop Contract

  • Second preimage attack articles [1, 2]

Already Claimed Check

⌨️ Already Claimed Check

Merkle Tree Scripts

⌨️ Merkle Tree Scripts

Writing the Tests

⌨️ Writing the Tests

Deployment Script

⌨️ Deployment Script

Adding Signature Verification

⌨️ Adding Signature Verification

Signature Standards

⌨️ Signature Standards

ECDSA Signatures

⌨️ ECDSA Signatures


Transaction Types Introduction

⌨️ Transaction Types Introduction

Transaction Types

⌨️ Transaction Types

Blob Transactions

⌨️ Blob Transactions


  • Type 113 Transactions
  • Implementing Signatures
  • Modifying the Tests
  • Test on zkSync (optional)
  • Create Claiming Script
  • Creating a Signature
  • Splitting a Signature
  • Executing the Anvil Script
  • Deploy and Claim on zkSync Local Node
  • Deploy and Claim on zkSync Sepolia
  • Summary

Advanced Foundry Section 4 NFTs (TBD)

Advanced Foundry Section 5: Foundry Upgrades

💻 Code: https://github.com/Cyfrin/foundry-upgrades-cu

Introduction

⭐️ Section 5: Upgradable Contracts & Proxies

Upgradable Smart Contracts Overview

Types of Upgrades

  1. Parameter
  2. Social Migrate
  3. Proxy
    1. Proxy Gotchas
      1. Function Collisions
      2. Storage Collisions
    2. Metamorphic Upgrades
    3. Transparent
    4. UUPS
    5. Diamond

Delegatecall

⌨️ Delegatecall

Small Proxy Example

⌨️ Small Proxy Example

Universal Upgradable Smart Contract

Setup

⌨️ UUPS Setup

Deploy

⌨️ Deploy

UpgradeBox

⌨️ Upgradebox

Test/Demo

⌨️ (5:53:48) | Test/Demo

Testnet Demo

⌨️ Testnet Demo

Advanced Foundry Section 5 NFTs

(back to top) ⬆️

Advanced Foundry Section 6: Foundry Account Abstraction

💻 Code: https://github.com/Cyfrin/minimal-account-abstraction

What is account abstraction?

⌨️ Account Abstraction Introduction

  • What is native account abstraction?
  • How does zkSync do account abstraction?
  • What is EIP-4337?
  • What are zkSync system contracts?

Code Overview

⌨️ Code Overview

Ethereum Setup

⌨️ Etheren Account Abstraction

PackedUserOperation

⌨️ PackedUserOperation

Validate UserOp

⌨️ Validate UserOp

EntryPoint Contract

⌨️ EntryPoint Contract

Execute Function Ethereum

⌨️ Execute

Deployment Script for an Ethereum Account

⌨️ Deploy Script

Tests Owner can Execute

⌨️ Tests Owner can Execute

Unsigned PackedUserOperation Test

⌨️ Get Unsigened PackedUserOperation

Signed UserOp Test

⌨️ Signed PackedUserOperation

Using unlocked accounts for local development

⌨️ Local Dev Unlocked

Test Validation of User Ops

⌨️ Test Validate UserOps

Test Entry Point

⌨️ Test Entry Point

Advanced Debugging

⌨️ Advanced Debugging

Mid-session Recap

⌨️ Mid Session Recap

Live Demo on Arbitrum

⌨️ Live Demo

ZkSync Native Account Abstraction

⌨️ ZkSync Setup

IAccount

⌨️ IAccount

System Contracts

⌨️ System Contracts

Type 113 LifeCycle

⌨️ TxType 113 Lifecycle

Mid-zkSync Recap

⌨️ ZkSync Accounts Recap

System Contract Call zkSync Simulations

⌨️ ZkSync Transaction Simulations

Validate Transaction zkSync

⌨️ ValidateTransaction

Execute Function Zksync

⌨️ executeTransaction

Pay For Transaction zkSync

⌨️ payForTransaction

Execute Transaction From Outside

⌨️ executeTransactionFromOutside

zkSync Tests

⌨️ zkSync Tests

Building a Transaction Struct

⌨️ Transaction Struct

Via Ir

⌨️ --via-ir

Validate Transaction Test

⌨️ Validate Transaction Test

Clean Up zkSync

⌨️ Clean up

Testnet zkSync Demo

⌨️ Testnet Demo

Rcap & End

⌨️ Recap End

Advanced Foundry Section 6 NFTs (TBD)

Advanced Foundry Section 7: Foundry DAO / Governance

Plutocracy is bad! Don't default to ERC20 token voting!!

💻 Code: https://github.com/Cyfrin/foundry-dao-cu

Introduction

⭐️ Section 14 | DAOs & Governance

What is a DAO?

How to build a DAO

DAOs toolings - Introduction to Aragon

⌨️ DAOs tooling - Special Guest from Aragon

Project Setup

⌨️ Build your own DAO Setup

Governance Token

⌨️ Governance Tokens

Governor

⌨️ Creating the Governor Contract

Tests

⌨️ Testing the Governor Contract

Wrap up

⌨️ Section Recap

Bonus: Gas optimization tips

Advanced Foundry Section 7 NFTs

(back to top) ⬆️

Advanced Foundry Section 8: Smart Contract Security & Auditing (For developers)

Developers 100% should know all about this! Don't leave the course without at least watching this section!

Important

We highly recommend you head over to the end-to-end Cyfrin Updraft Security and Auditing Curriculum.

🖥️ Code: https://github.com/PatrickAlphaC/denver-security

Introduction

⭐️ Section 6 | Security & Auditing

What is a smart contract audit?

⌨️ What is a smart contract audit?

Tools

⌨️ What tools do security professionals use?

Manual Review

⌨️ Intro to Manual review

Static Analysis

Dynamic Analysis

Formal Verification

Symbolic Execution

Fuzzing

Formal Verification (& Symbolic Execution)

Other security stuff

What does the process of manual review look like?

⌨️ Manual Review with Tincho

Formal Verification

⌨️ Formal Verification

Closing Thoughts

⌨️ Wrap. Up

Advanced Foundry Section 8 NFTs

(back to top) ⬆️

Congratulations

🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊 Completed all The Course! 🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊🎊

Where do I go now?

Learning More

Community

Hackathons

Be sure to check out project grant programs!

And make today an amazing day!

(back to top) ⬆️

Disclosures

Transparency is important! So we want to disclose any potential conflicts that might have affected my judgement so you can pick tools that are right for you. Patrick is co-founder of Alpha Chain, a blockchain infrastructure company. Alpha Chain runs Chainlink, Ethereum, Binance, Polygon, Harmony, Solana, Moonbeam, and Moonriver blockchain services. Alpha Chain often works with Alchemy and receives discounted services. Patrick is the co-founder of Cyfrin, and they do smart contract security & auditing services. Patrick is also the co-founder of Chain Accel, who is an advisor on the Peeranha project.

Because of all this, I have added alternatives to each section where we suggest a tool.

(back to top) ⬆️

Sponsors

A huge thank you to our sponsors. These are the groups and technologies

(back to top) ⬆️

Thank you

Thanks to everyone who is taking, participating in, and working on this course. It's been a passion project and a data dump of everything I've learnt in the web3 space to get you up to speed quickly. Also, a big thank you to Cyfrin & Chain Accel for encouraging this course to come to light, and many, many, many people from the community.

And thanks to the Cyfrin team for making this possible!

License

Cyfrin Updraft content is open-sourced licensed as GPLv3.

Cyfrin Twitter Cyfrin YouTube Cyfrin LinkedIn

(back to top) ⬆️

About

Cyfrin Foundry Course

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published