EIPs Explained

ERC-5568 · Review · ERC · 2022-08-31

ERC-5568: Well-Known Format for Required Actions

A standard way for a contract to tell a wallet "the user must do something first" (approve a token, make an HTTP request, rotate keys) via a well-known view function and a custom revert error.

What problem does it solve?

Often a transaction will fail unless the user does something first: approve an ERC-20 allowance, fetch data from a server, sign something. Today that knowledge lives in each dApp's frontend, which must hard-code every prerequisite.

ERC-5568 lets the contract itself tell the wallet what action is needed, in a compact machine-readable form, so a wallet can handle it generically.

How it works

Two pieces:

  1. Detection function, which the wallet simulates before sending:

    function walletSignal24(bytes32 selector, bytes function_data)
        view returns (uint24 instruction_id, bytes instruction_data);
    

    instruction_id = 0 means nothing is needed. A non-zero value names an instruction, and instruction_data holds its parameters.

  2. Custom revert error, used when an action was not taken (revert data relies on EIP-140 REVERT):

    error WalletSignal24(uint24 instruction_id, bytes instruction_data);
    

Rules:

  • An instruction's instruction_id should be the number of the ERC that defines it, and each ERC defines at most one. That ERC also defines the data layout.
  • The wallet must simulate walletSignal24 locally before broadcasting, treating it as able to change state.
  • If the wallet does not support the instruction, it must show an error. Otherwise it performs the instruction and re-evaluates the transaction, unless the instruction says not to.
  • Invalid or unparsable instructions must produce an error, with no re-evaluation.

ERC-165 is not used; a wallet detects support by simply calling the function.

Sample code

Wallet-side check before sending a transaction (ethers v6):

import { Contract, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const abi = [
  "function walletSignal24(bytes32 selector, bytes function_data) view returns (uint24, bytes)",
];

async function requiredAction(to: string, data: string) {
  const c = new Contract(to, abi, provider);
  const selector = data.slice(0, 10).padEnd(66, "0"); // 4-byte selector, right-padded to bytes32
  try {
    const [id, payload] = await c.walletSignal24.staticCall(selector, "0x" + data.slice(10));
    return id === 0n ? null : { id: Number(id), payload };
  } catch {
    return null; // contract does not implement ERC-5568
  }
}

How the selector is packed into bytes32 and whether function_data includes it are not spelled out in the spec; this example is one reasonable reading.

Things to know

  • Status is Review; the format may still change.
  • This ERC defines only the signalling envelope. Concrete instructions (and their data formats) must be defined by other ERCs.
  • ERC-3668 (CCIP Read) solves a related problem, fetching off-chain data, with a different revert-based mechanism; the two can coexist.
  • The spec considers collisions with existing custom errors unlikely and mostly harmless.

#wallet #revert #ux #interface

Details

Authors
Gavin John (@Pandapip1)
Status
Review
Type
Standards Track / ERC
Created
2022-08-31
Requires
Required by

Machine-readable: Markdown · JSON