Created
March 11, 2018 10:27
-
-
Save ayinot/1d4df5cd1cbbc44fd1f11919d7c301fa to your computer and use it in GitHub Desktop.
A contract to understand Function Modifers
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
pragma solidity ^0.4.15; | |
//@Title to understand FunctionModifiers | |
//@Author Toniya <[email protected]> | |
// It changes the behaviour of the function | |
//Eg Contract kill function should only be called by the admin | |
contract FunctionModifiers { | |
address public creator; | |
function FunctionModifiers() { | |
creator = msg.sender; | |
} | |
//Defining the modifiers | |
modifier onlyCreator() { | |
//If a condition is not met then throw error | |
if(msg.sender!=creator) throw; | |
//Or just continue the excecution | |
_; | |
} | |
function addNos(uint a,uint b) constant returns(uint sum) { | |
sum = a+b; | |
return sum; | |
} | |
// the below function should be allowed only by the creator | |
function kill() onlyCreator { | |
selfdestruct(creator); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment