SOCI4L

Refuse in fewer bytes

Step 1 of 3
0 of 2 goals

Name the failure

That message is a string literal. It ships inside your deployed bytecode and you pay for every character of it, forever.

Declare an error instead, above the functions:

error BelowMinimum(uint256 sent, uint256 minimum);

An error can carry values. A string cannot.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Sale {
    uint256 public constant MIN = 100;
    uint256 public raised;

    function contribute(uint256 amount) external {
        require(amount >= MIN, "contribution is below the minimum allowed");
        raised += amount;
    }
}

Goals

The contract compiles
nothing to compile yet
Declare `error BelowMinimum`
nothing compiles yet

Contract storage

Write a contract and it will deploy itself here.