---
eip: 5559
label: ERC-5559
title: Cross Chain Write Deferral Protocol
status: Stagnant
type: Standards Track
category: ERC
created: 2022-06-23
requires: 712
official: https://eips.ethereum.org/EIPS/eip-5559
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5559.md
canonical: https://eips.huatuo.xyz/eip-5559/
lang: en
tldr: "Proposed the write-side counterpart to CCIP Read: an L1 contract reverts with a typed error telling the client to send the update to an L2 contract or to a signed off-chain database instead."
tags: [cross-chain, l2, offchain, ens, ccip, eip712]
---

# ERC-5559: Cross Chain Write Deferral Protocol

> The cross chain write deferral protocol provides a mechanism to defer the storage & resolution of mutations to off-chain handlers

**TL;DR:** Proposed the write-side counterpart to CCIP Read: an L1 contract reverts with a typed error telling the client to send the update to an L2 contract or to a signed off-chain database instead.

## What problem does it solve?

[EIP-3668](/eip-3668/) (CCIP Read) lets a mainnet contract say "the answer lives off-chain, fetch it here and verify it", which is how ENS names can resolve data stored on L2s or in databases. But there was no matching standard for **writes**: if a name's records live on an L2 or in a database, how does a wallet know where to send an update?

ERC-5559 defines that. Users and apps keep talking to the familiar L1 contract and the same function signatures, while the contract redirects mutations to cheaper storage.

## How it works

The client calls the L1 contract as usual (for example `setAddr(node, addr)`), usually as a preflight `eth_call` or gas estimate. The contract either performs the write, or **reverts with a typed error** telling the client where the write really belongs:

- **`StorageHandledByL2(chainId, contractAddress)`**: the client sends a new transaction with the **same calldata** to `contractAddress` on the EVM chain `chainId`, via an RPC of its choice. The L2 contract can use normal `msg.sender` checks.
- **`StorageHandledByOffChainDatabase(sender, url, data)`**: `sender` is an [EIP-712](/eip-712/) domain (name, version, chainId, verifyingContract) and `data` is a message holding the function selector, the user's address, the parameters as name/value string pairs and an expiry timestamp. The user signs it with EIP-712 and POSTs `{ sender, data, signature }` as JSON to `url`. The gateway must check the signature and permissions.

Deferrals can chain: an L1 contract can point to an L2 contract, which in turn defers to a database. Contracts must emit events when they change the handler chain ID, L2 address or database URL.

## Sample code

Client handling of an L2 deferral (ethers v6):

```ts
import { Contract, Interface, JsonRpcProvider, Wallet } from "ethers";

const iface = new Interface([
  "function setAddr(bytes32 node, address a)",
  "error StorageHandledByL2(uint256 chainId, address contractAddress)",
]);
const resolver = new Contract(resolverAddress, iface, l1Signer);

try {
  await resolver.setAddr.staticCall(node, newAddr);   // preflight
  await (await resolver.setAddr(node, newAddr)).wait(); // stored on L1
} catch (err: any) {
  const parsed = iface.parseError(err.data);
  if (parsed?.name !== "StorageHandledByL2") throw err;
  const [chainId, target] = parsed.args;
  const l2 = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(rpcFor(chainId)));
  // resend the original calldata, unchanged, to the L2 handler
  const data = iface.encodeFunctionData("setAddr", [node, newAddr]);
  await (await l2.sendTransaction({ to: target, data })).wait();
}
```

Solidity side of the same deferral:

```solidity
error StorageHandledByL2(uint256 chainId, address contractAddress);

function setAddr(bytes32, address) external view {
    revert StorageHandledByL2(l2ChainId, l2Resolver);
}
```

## Things to know

- **Status: Stagnant.** The proposal was not finalised. CCIP Read ([EIP-3668](/eip-3668/)), which it builds on, is Final.
- Clients must refuse a deferral that points back to Ethereum mainnet, and must reuse the original calldata for L2 deferrals, to avoid being tricked into signing a different, malicious transaction.
- Off-chain database writes include the user's address and come from the user's IP, which can fingerprint wallets. The spec recommends letting users choose on-chain storage and letting client libraries proxy, allowlist or block these requests.
- An off-chain database offers no onchain guarantees; trust rests entirely on the gateway operator.
- Clients that don't implement the protocol simply see a revert.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-5559
