Solidity Modifiers

Function modifiers can be used to automatically check a condition before executing a function, serving various use cases. These modifiers can be executed before or after the function's code, and are necessary when a specific condition is not met. If the given condition is not met, the function will not be executed.

Two variations of a function modifier

1. Function modifier with an argument:

modifier  modifier_name(unit arg)
{
   // action to be taken
}

2. Function modifier without argument:

modifier  modifier_name()
{
   // action to be taken
}

What is Merge Wildcard?

The _; symbol is known as Merge Wildcard and this is replaced by the function definition during execution.

  • In other words, after this wildcard has been used, the control is moved to the location where the appropriate function definition is located.
  • This symbol is mandatory for all modifiers.
  • The modifier may contain this wildcard anywhere.
  • When the wildcard is placed at the end of the modifier, the condition is verified and the appropriate function is executed if it is satisfied.
  • When it is placed at the beginning, the appropriate function is executed first followed by the condition verification.
Video : Solidity Modifiers
Resource File
Question / Answer

The _; symbol is known as Merge Wildcard and this is replaced by the function definition during execution.