Prompt Web3
  • 🤓Web3 Refresher Course with GptTutor
  • Creating your own Custom personas
  • Creating The Web3 GptTutor
  • Prompting the course sylibus
  • Prompting new lessons
  • Expanding parts of a lesson
  • Lesson 1
    • Lesson 1: Outline
    • Lesson 1: Assignments & Exercises
      • A1: Smart contracts in the real world
      • E1: HelloWorld.sol
  • Lesson 2
    • Lesson 2: Outline
    • Lesson 2: Assignments & Exercises
      • A1: Ethereum gas costs, data types and control structures - A brief take
      • E1: AssetManagement.sol
    • Lesson 2: Final notes and code repos
  • Lesson 3
    • Lesson 3: Outline
    • Lesson 3: Assignments & Excercises
      • A1 - Notes on View and Pure modifiers in Solidity
      • E1: EthWallet.sol
      • E1: Hardhat Tests
      • E1: NextJs Front End
    • Lesson 3: Final notes & Final project + repo
  • Lesson 4
    • Lesson 4: Outline
    • Lesson 4: Assignments & Exercises
      • A1 - Solidity error handling - notes on require, revert and assert
      • E1: EthWallet.sol - Update
      • E1 - EthWallet.test.js - Update
      • E1: NextJs Front End - Update
    • Lesson 4: Final notes & Final project + repo
  • Lesson 5
    • Lesson 5: Outline
    • Lesson 5: Assignments & Exercises
      • A1 - Using structs and mappings to manage complex data in Solidity
      • E1 - OrderSystem.sol
      • E1 - OrderSystem.test.js
    • Lesson 5: Final notes & Project Repo
  • LESSON 6
    • Lesson 6: Outline
    • Lesson 6: Assignments & Exercises
      • A1 - Solidity Interfaces - Facilitating interaction, modularity and Dapp upgradability
      • E1 - Ranked Choice Voting system
        • E1 - BallotContract.sol
        • E1 - IBallotContract.sol
        • E1 - VotingContract.sol
        • E1 - RCVotingSystem.test.js
      • E1 - Feedback
    • Lesson 6: Final notes & Project Repo
  • Lesson 7
    • Lesson 7: Outline
    • Lesson 7: Assignments & Exercises
      • E1 - Uniswap Flashswap dual Arbitrage Bot
        • E1 - FlashSwapV3.sol
        • E1 - dualArbScan.js
        • E1 - arbQuote.js
      • Lesson 7: Final notes & Project Repo
Powered by GitBook
On this page
  • Lesson 3: Functions and Modifiers in Solidity
  • Part 1: Functions in Solidity
  • Part 2: Modifiers in Solidity
  1. Lesson 3

Lesson 3: Outline

Lesson 3 introduction and outline.

Lesson 3: Functions and Modifiers in Solidity

Objective: To understand how to write and use functions in Solidity, and to learn about function modifiers for enforcing certain conditions and managing access control in smart contracts.

Part 1: Functions in Solidity

  • Function Declaration and Types:

    • Understand the syntax for declaring functions.

    • Different types of functions: public, private, internal, and external.

  • Return Values and Visibility:

    • How to define return values for functions.

    • Understand the implications of function visibility.

  • Function Modifiers:

    • Usage of view, pure, and state-changing functions.

  • Function Parameters:

    • Passing parameters to functions.

    • Using memory and storage keywords for complex data types.

  • Example: Creating a Function

    pragma solidity ^0.8.0;
    
    contract MyContract {
        uint public count = 0;
    
        function increment() public {
            count += 1;
        }
    
        function getCount() public view returns (uint) {
            return count;
        }
    }

Part 2: Modifiers in Solidity

  • Understanding Modifiers:

    • Purpose of modifiers in Solidity.

    • Writing custom modifiers to enforce conditions.

  • Common Use Cases:

    • Restricting access to certain functions.

    • Validating inputs or conditions before executing function logic.

  • Example: Using a Modifier

    pragma solidity ^0.8.0;
    
    contract MyContract {
        address public owner;
    
        constructor() {
            owner = msg.sender;
        }
    
        modifier onlyOwner() {
            require(msg.sender == owner, "Not the owner");
            _;
        }
    
        function changeOwner(address newOwner) public onlyOwner {
            owner = newOwner;
        }
    }
PreviousLesson 2: Final notes and code reposNextLesson 3: Assignments & Excercises

Last updated 1 year ago