December 2018
Intermediate to advanced
222 pages
6h 6m
English
In solidity, the modifier is used to change the behavior of a function. They can automatically check a condition prior to executing the function. Here is an example, as follows:
pragma solidity ^0.4.24;contract Modifiers { address public admin; function construct () public { admin = msg.sender; } //define the modifiers modifier onlyAdmin() { // if a condition is not met then throw an exception if (msg.sender != admin) revert(); // or else just continue executing the function _; } // apply modifiers function kill() onlyAdmin public { selfdestruct(admin); }}
Read now
Unlock full access