Skip to content

Instantly share code, notes, and snippets.

@ayinot
Created March 11, 2018 10:27
Show Gist options
  • Save ayinot/1d4df5cd1cbbc44fd1f11919d7c301fa to your computer and use it in GitHub Desktop.
Save ayinot/1d4df5cd1cbbc44fd1f11919d7c301fa to your computer and use it in GitHub Desktop.
A contract to understand Function Modifers
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