solhint

gas-custom-errors

Recommended Badge Category Badge Default Severity Badge warn

The {“extends”: “solhint:recommended”} property in a configuration file enables this rule.

Description

Enforces the use of Custom Errors over Require and Revert statements

Options

This rule accepts a string option of rule severity. Must be one of “error”, “warn”, “off”. Default to warn.

Example Config

{
  "rules": {
    "gas-custom-errors": "warn"
  }
}

Notes

Examples

👍 Examples of correct code for this rule

Use of Custom Errors

revert CustomErrorFunction();

Use of Custom Errors with arguments

revert CustomErrorFunction({ msg: "Insufficient Balance" });

👎 Examples of incorrect code for this rule

Use of require statement

require(userBalance >= availableAmount, "Insufficient Balance");

Use of plain revert statement

revert();

Use of revert statement with message

revert("Insufficient Balance");

Version

This rule was introduced in Solhint 4.5.0

Resources