EIPs Explained

ERC-1066 · Stagnant · ERC · 2018-05-05

ERC-1066: Status Codes

A shared, HTTP-like table of one-byte status codes that contracts can return so other contracts, tools and users understand what happened beyond a bare true/false.

What problem does it solve?

Most contracts either revert on anything that is not a clean success, or return a plain bool. Neither tells a calling contract much: was the request refused, delayed, still pending, or simply unnecessary? Revert strings help humans, but code cannot reliably react to arbitrary text.

ERC-1066 proposes a common vocabulary of status codes, in the spirit of HTTP's 200/404/503, so that contracts can signal richer outcomes, callers can branch on them automatically, and wallets can show meaningful (even translated) messages.

How it works

A status is a single byte, returned on its own or as the first value of a multi-value return. The byte is read as a 16 x 16 grid:

  • The high nibble is the category.
  • The low nibble is the reason, and the reasons line up across categories (x0 failure, x1 success, x2 awaiting others, x4 lower limit, x6 upper limit, xF metadata, and so on).
Range Category Examples
0x0* Generic 0x00 Failure, 0x01 Success, 0x02 Awaiting Others
0x1* Permission & Control 0x10 Disallowed, 0x11 Allowed
0x2* Find, Inequalities & Range 0x20 Not Found, 0x21 Found
0x3* Negotiation & Governance 0x34 Quorum Not Reached, 0x38 Already Voted
0x4* Availability & Time 0x42 Paused, 0x44 Not Available Yet, 0x46 Expired
0x5* Tokens, Funds & Finance 0x50 Transfer Failed, 0x54 Insufficient Funds
0xA* Application-specific 0xA0 App-Specific Failure
0xE* Encryption, Identity & Proofs 0xE3 Signed, 0xE5 Signature Required
0xF* Off-chain 0xF2 Awaiting Off-Chain Process

Ranges 0x6*–0x9* and 0xB*–0xD* are left unspecified, and unlisted codes inside a range are reserved for future specification, not free for arbitrary use. Human-readable text for each code was meant to come from a companion registry, ERC-1444.

Sample code

Replacing a boolean with a status byte, so the caller can tell "not yet" from "not allowed":

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

contract Counter {
    uint256 public immutable startTime;
    mapping(address => bool) public registered;
    mapping(address => uint256) public counters;

    constructor(uint256 start) { startTime = start; }

    function register() external { registered[msg.sender] = true; }

    function increase() external returns (bytes1 status) {
        if (block.timestamp < startTime) return 0x44; // Not Available Yet
        if (!registered[msg.sender]) return 0x10;    // Disallowed
        counters[msg.sender] += 1;
        return 0x01;                                 // Success
    }
}

A caller can then react without parsing strings, e.g. retry later on 0x44 but give up on 0x10.

Things to know

  • Status: Stagnant. The code table never became a widely used convention; most contracts today use revert with custom errors instead.
  • Status codes are meant to complement reverting, not replace it. A contract can still revert, and can include the code in the revert data.
  • Returning a code instead of reverting means state changes are kept. Callers must check the code; ignoring it is as dangerous as ignoring an unchecked bool.

#status-codes #errors #ux #interoperability

Details

Authors
Brooklyn Zelenka (@expede), Tom Carchrae (@carchrae), Gleb Naumenko (@naumenkogs)
Status
Stagnant
Type
Standards Track / ERC
Created
2018-05-05
Required by

Machine-readable: Markdown · JSON