Created
January 30, 2023 17:25
-
-
Save ArslanKathia/40557ecedb083c0034c3a24e03d1683f to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8; | |
contract modifiers{ | |
address public owner = msg.sender; | |
uint public _xx = 10; | |
//modifier is used to reuse the same code from the starting or ending of the function | |
modifier onlyOwner(){ | |
require(owner == msg.sender,"You are not the owner"); | |
_; //this _; means that go back to that function from where modifier is called | |
} | |
modifier reuseCode(){ | |
for(uint i=0;i<10;i++){ | |
//code | |
} | |
_; | |
} | |
function startAuction() public onlyOwner { //first call the modifier than function next code.. | |
//code | |
//after this code execution go back to modifier again to check if further something actions on it | |
//if not than function ends | |
_xx = _xx+10; | |
} | |
function stopAuction() public view onlyOwner{ | |
//code | |
} | |
function checkStatus() public view onlyOwner{ | |
//code | |
} | |
//calling input modifier example | |
uint public age = 18; | |
modifier checkAge(uint _x){ | |
age = age + _x; | |
_; | |
} | |
function checkingAge(uint _y) public checkAge(_y){ | |
//next code after modifier calling | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment