{"eip":5559,"title":"Cross Chain Write Deferral Protocol","description":"The cross chain write deferral protocol provides a mechanism to defer the storage \u0026 resolution of mutations to off-chain handlers","authors":["Paul Gauvreau (@0xpaulio)","Nick Johnson (@arachnid)"],"status":"Stagnant","type":"Standards Track","category":"ERC","created":"2022-06-23","requires":[712],"discussionsTo":"https://ethereum-magicians.org/t/eip-cross-chain-write-deferral-protocol/10576","repo":"ERCs","label":"ERC-5559","officialUrl":"https://eips.ethereum.org/EIPS/eip-5559","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5559.md","url":"https://eips.huatuo.xyz/eip-5559/","tldr":{"en":"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.","ja":"CCIP Read の書き込み側に相当するものを提案しました。L1 コントラクトが型付きエラーでリバートし、代わりに L2 コントラクトまたは署名付きのオフチェーンデータベースへ更新を送るようクライアントに伝えます。","ko":"CCIP Read의 쓰기 측 대응 표준을 제안했습니다. L1 컨트랙트가 타입이 지정된 에러로 리버트해, 클라이언트에게 업데이트를 대신 L2 컨트랙트나 서명된 오프체인 데이터베이스로 보내라고 알려줍니다.","zh":"提议了 CCIP Read 的写入侧对应方案：L1 合约以带类型的错误回滚，告诉客户端把更新改发到 L2 合约或带签名的链下数据库。"},"tags":["cross-chain","l2","offchain","ens","ccip","eip712"],"explainers":{"en":{"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"],"related":[3668,712,137],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-5559/","markdown":"## What problem does it solve?\n\n[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?\n\nERC-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.\n\n## How it works\n\nThe 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:\n\n- **`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.\n- **`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.\n\nDeferrals 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.\n\n## Sample code\n\nClient handling of an L2 deferral (ethers v6):\n\n```ts\nimport { Contract, Interface, JsonRpcProvider, Wallet } from \"ethers\";\n\nconst iface = new Interface([\n  \"function setAddr(bytes32 node, address a)\",\n  \"error StorageHandledByL2(uint256 chainId, address contractAddress)\",\n]);\nconst resolver = new Contract(resolverAddress, iface, l1Signer);\n\ntry {\n  await resolver.setAddr.staticCall(node, newAddr);   // preflight\n  await (await resolver.setAddr(node, newAddr)).wait(); // stored on L1\n} catch (err: any) {\n  const parsed = iface.parseError(err.data);\n  if (parsed?.name !== \"StorageHandledByL2\") throw err;\n  const [chainId, target] = parsed.args;\n  const l2 = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(rpcFor(chainId)));\n  // resend the original calldata, unchanged, to the L2 handler\n  const data = iface.encodeFunctionData(\"setAddr\", [node, newAddr]);\n  await (await l2.sendTransaction({ to: target, data })).wait();\n}\n```\n\nSolidity side of the same deferral:\n\n```solidity\nerror StorageHandledByL2(uint256 chainId, address contractAddress);\n\nfunction setAddr(bytes32, address) external view {\n    revert StorageHandledByL2(l2ChainId, l2Resolver);\n}\n```\n\n## Things to know\n\n- **Status: Stagnant.** The proposal was not finalised. CCIP Read ([EIP-3668](/eip-3668/)), which it builds on, is Final.\n- 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.\n- 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.\n- An off-chain database offers no onchain guarantees; trust rests entirely on the gateway operator.\n- Clients that don't implement the protocol simply see a revert.\n"},"ja":{"lang":"ja","tldr":"CCIP Read の書き込み側に相当するものを提案しました。L1 コントラクトが型付きエラーでリバートし、代わりに L2 コントラクトまたは署名付きのオフチェーンデータベースへ更新を送るようクライアントに伝えます。","tags":["cross-chain","l2","offchain","ens","ccip","eip712"],"related":[3668,712,137],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-5559/","markdown":"## 何を解決するのか\n\n[EIP-3668](/eip-3668/)（CCIP Read）は、メインネットのコントラクトが「答えはオフチェーンにあるので、ここから取得して検証してください」と伝えられるようにするもので、これにより ENS 名は L2 やデータベースに保存されたデータを解決できます。しかし、**書き込み**に対応する標準はありませんでした。名前のレコードが L2 やデータベースにある場合、ウォレットは更新をどこに送ればよいかをどう知るのでしょうか。\n\nERC-5559 がそれを定義します。ユーザーとアプリは、おなじみの L1 コントラクトと同じ関数シグネチャを使い続け、コントラクトが変更をより安価なストレージへリダイレクトします。\n\n## 仕組み\n\nクライアントは通常どおり L1 コントラクトを呼び出します（たとえば `setAddr(node, addr)`）。たいていは事前確認の `eth_call` かガス見積もりとして行います。コントラクトは書き込みを実行するか、書き込みが本来どこに属するかをクライアントに伝える**型付きエラーでリバート**します。\n\n- **`StorageHandledByL2(chainId, contractAddress)`**: クライアントは、EVM チェーン `chainId` 上の `contractAddress` に、**同じ calldata** で新しいトランザクションを、任意の RPC 経由で送ります。L2 コントラクトは通常の `msg.sender` チェックを使えます。\n- **`StorageHandledByOffChainDatabase(sender, url, data)`**: `sender` は [EIP-712](/eip-712/) のドメイン（name、version、chainId、verifyingContract）で、`data` は関数セレクター、ユーザーのアドレス、名前と値の文字列ペアとしてのパラメータ、有効期限のタイムスタンプを含むメッセージです。ユーザーはこれに EIP-712 で署名し、`{ sender, data, signature }` を JSON として `url` に POST します。ゲートウェイは署名と権限を確認しなければなりません。\n\n委任は連鎖できます。L1 コントラクトが L2 コントラクトを指し、その L2 コントラクトがさらにデータベースに委任することもあります。コントラクトは、ハンドラーのチェーン ID、L2 アドレス、データベース URL を変更するときにイベントを発行しなければなりません。\n\n## サンプルコード\n\nL2 への委任に対するクライアントの処理（ethers v6）:\n\n```ts\nimport { Contract, Interface, JsonRpcProvider, Wallet } from \"ethers\";\n\nconst iface = new Interface([\n  \"function setAddr(bytes32 node, address a)\",\n  \"error StorageHandledByL2(uint256 chainId, address contractAddress)\",\n]);\nconst resolver = new Contract(resolverAddress, iface, l1Signer);\n\ntry {\n  await resolver.setAddr.staticCall(node, newAddr);   // preflight\n  await (await resolver.setAddr(node, newAddr)).wait(); // stored on L1\n} catch (err: any) {\n  const parsed = iface.parseError(err.data);\n  if (parsed?.name !== \"StorageHandledByL2\") throw err;\n  const [chainId, target] = parsed.args;\n  const l2 = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(rpcFor(chainId)));\n  // resend the original calldata, unchanged, to the L2 handler\n  const data = iface.encodeFunctionData(\"setAddr\", [node, newAddr]);\n  await (await l2.sendTransaction({ to: target, data })).wait();\n}\n```\n\n同じ委任の Solidity 側:\n\n```solidity\nerror StorageHandledByL2(uint256 chainId, address contractAddress);\n\nfunction setAddr(bytes32, address) external view {\n    revert StorageHandledByL2(l2ChainId, l2Resolver);\n}\n```\n\n## 知っておくべきこと\n\n- **ステータス: Stagnant。** この提案は最終確定されませんでした。基になっている CCIP Read（[EIP-3668](/eip-3668/)）は Final です。\n- クライアントは、Ethereum メインネットに戻るような委任を拒否しなければならず、L2 への委任では元の calldata を再利用しなければなりません。これは、別の悪意あるトランザクションに署名させられることを避けるためです。\n- オフチェーンデータベースへの書き込みにはユーザーのアドレスが含まれ、ユーザーの IP から送られるため、ウォレットのフィンガープリントになりえます。仕様は、ユーザーがオンチェーンストレージを選べるようにし、クライアントライブラリがこれらのリクエストをプロキシ、許可リスト化、ブロックできるようにすることを推奨しています。\n- オフチェーンデータベースにはオンチェーンの保証はなく、信頼はすべてゲートウェイの運営者にかかっています。\n- このプロトコルを実装していないクライアントには、単にリバートとして見えます。\n"},"ko":{"lang":"ko","tldr":"CCIP Read의 쓰기 측 대응 표준을 제안했습니다. L1 컨트랙트가 타입이 지정된 에러로 리버트해, 클라이언트에게 업데이트를 대신 L2 컨트랙트나 서명된 오프체인 데이터베이스로 보내라고 알려줍니다.","tags":["cross-chain","l2","offchain","ens","ccip","eip712"],"related":[3668,712,137],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-5559/","markdown":"## 어떤 문제를 해결하나요?\n\n[EIP-3668](/eip-3668/)(CCIP Read)은 메인넷 컨트랙트가 \"답은 오프체인에 있으니 여기서 가져와 검증하세요\"라고 말할 수 있게 해주며, ENS 이름이 L2나 데이터베이스에 저장된 데이터를 해석할 수 있는 것도 이 덕분입니다. 하지만 **쓰기**에 대응하는 표준은 없었습니다. 이름의 레코드가 L2나 데이터베이스에 있다면, 지갑은 업데이트를 어디로 보내야 하는지 어떻게 알까요?\n\nERC-5559가 이를 정의합니다. 사용자와 앱은 익숙한 L1 컨트랙트와 같은 함수 시그니처로 계속 통신하고, 컨트랙트는 변경 작업을 더 저렴한 스토리지로 리다이렉트합니다.\n\n## 어떻게 동작하나요?\n\n클라이언트는 평소처럼 L1 컨트랙트를 호출합니다(예: `setAddr(node, addr)`). 보통 사전 점검용 `eth_call`이나 가스 추정으로 호출합니다. 컨트랙트는 쓰기를 직접 수행하거나, 쓰기가 실제로 어디에 속하는지 클라이언트에게 알려주는 **타입이 지정된 에러로 리버트**합니다.\n\n- **`StorageHandledByL2(chainId, contractAddress)`**: 클라이언트는 원하는 RPC를 통해 EVM 체인 `chainId`의 `contractAddress`로 **같은 calldata**를 담은 새 트랜잭션을 보냅니다. L2 컨트랙트는 일반적인 `msg.sender` 검사를 사용할 수 있습니다.\n- **`StorageHandledByOffChainDatabase(sender, url, data)`**: `sender`는 [EIP-712](/eip-712/) 도메인(name, version, chainId, verifyingContract)이고, `data`는 함수 셀렉터, 사용자 주소, 이름/값 문자열 쌍으로 된 파라미터, 만료 타임스탬프를 담은 메시지입니다. 사용자가 이를 EIP-712로 서명하고 `{ sender, data, signature }`를 JSON으로 `url`에 POST합니다. 게이트웨이는 서명과 권한을 확인해야 합니다.\n\n위임은 연쇄될 수 있습니다. L1 컨트랙트가 L2 컨트랙트를 가리키고, 그 L2 컨트랙트가 다시 데이터베이스에 위임할 수 있습니다. 컨트랙트는 핸들러의 체인 ID, L2 주소, 데이터베이스 URL을 변경할 때 이벤트를 발생시켜야 합니다.\n\n## 샘플 코드\n\nL2 위임을 처리하는 클라이언트(ethers v6):\n\n```ts\nimport { Contract, Interface, JsonRpcProvider, Wallet } from \"ethers\";\n\nconst iface = new Interface([\n  \"function setAddr(bytes32 node, address a)\",\n  \"error StorageHandledByL2(uint256 chainId, address contractAddress)\",\n]);\nconst resolver = new Contract(resolverAddress, iface, l1Signer);\n\ntry {\n  await resolver.setAddr.staticCall(node, newAddr);   // preflight\n  await (await resolver.setAddr(node, newAddr)).wait(); // stored on L1\n} catch (err: any) {\n  const parsed = iface.parseError(err.data);\n  if (parsed?.name !== \"StorageHandledByL2\") throw err;\n  const [chainId, target] = parsed.args;\n  const l2 = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(rpcFor(chainId)));\n  // resend the original calldata, unchanged, to the L2 handler\n  const data = iface.encodeFunctionData(\"setAddr\", [node, newAddr]);\n  await (await l2.sendTransaction({ to: target, data })).wait();\n}\n```\n\n같은 위임의 Solidity 측:\n\n```solidity\nerror StorageHandledByL2(uint256 chainId, address contractAddress);\n\nfunction setAddr(bytes32, address) external view {\n    revert StorageHandledByL2(l2ChainId, l2Resolver);\n}\n```\n\n## 알아둘 점\n\n- **상태: Stagnant.** 이 제안은 최종 확정되지 않았습니다. 기반이 되는 CCIP Read([EIP-3668](/eip-3668/))는 Final입니다.\n- 클라이언트는 이더리움 메인넷으로 되돌아가는 위임을 거부해야 하고, L2 위임에서는 원래 calldata를 그대로 재사용해야 합니다. 다른 악성 트랜잭션에 서명하도록 속는 일을 막기 위해서입니다.\n- 오프체인 데이터베이스 쓰기에는 사용자의 주소가 포함되고 사용자의 IP에서 전송되므로 지갑을 식별하는 지문이 될 수 있습니다. 명세는 사용자가 온체인 스토리지를 선택할 수 있게 하고, 클라이언트 라이브러리가 이런 요청을 프록시하거나 허용 목록에 넣거나 차단할 수 있게 할 것을 권장합니다.\n- 오프체인 데이터베이스는 온체인 보장을 전혀 제공하지 않으며, 신뢰는 전적으로 게이트웨이 운영자에게 달려 있습니다.\n- 이 프로토콜을 구현하지 않은 클라이언트는 단순히 리버트로 보게 됩니다.\n"},"zh":{"lang":"zh","tldr":"提议了 CCIP Read 的写入侧对应方案：L1 合约以带类型的错误回滚，告诉客户端把更新改发到 L2 合约或带签名的链下数据库。","tags":["cross-chain","l2","offchain","ens","ccip","eip712"],"related":[3668,712,137],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-5559/","markdown":"## 它解决什么问题？\n\n[EIP-3668](/eip-3668/)（CCIP Read）让主网合约可以说\"答案在链下，到这里获取并验证\"，ENS 名称正是借此解析存储在 L2 或数据库中的数据。但**写入**一直没有对应的标准：如果某个名称的记录存放在 L2 或数据库中，钱包怎么知道该把更新发到哪里？\n\nERC-5559 定义了这一点。用户和应用继续与熟悉的 L1 合约交互，使用相同的函数签名，而合约会把修改重定向到更便宜的存储。\n\n## 它如何运作\n\n客户端照常调用 L1 合约（例如 `setAddr(node, addr)`），通常是作为预检的 `eth_call` 或 gas 估算。合约要么执行写入，要么**以带类型的错误回滚**，告诉客户端写入真正应该去哪里：\n\n- **`StorageHandledByL2(chainId, contractAddress)`**：客户端通过自己选择的 RPC，向 EVM 链 `chainId` 上的 `contractAddress` 发送一笔使用**相同 calldata** 的新交易。L2 合约可以使用常规的 `msg.sender` 检查。\n- **`StorageHandledByOffChainDatabase(sender, url, data)`**：`sender` 是一个 [EIP-712](/eip-712/) 域（name、version、chainId、verifyingContract），`data` 是一条消息，包含函数选择器、用户地址、以名称/值字符串对表示的参数，以及过期时间戳。用户用 EIP-712 对其签名，并把 `{ sender, data, signature }` 以 JSON 形式 POST 到 `url`。网关必须检查签名和权限。\n\n转交可以串联：L1 合约可以指向 L2 合约，而 L2 合约又转交给数据库。合约在更改处理方的链 ID、L2 地址或数据库 URL 时必须触发事件。\n\n## 示例代码\n\n客户端处理 L2 转交（ethers v6）：\n\n```ts\nimport { Contract, Interface, JsonRpcProvider, Wallet } from \"ethers\";\n\nconst iface = new Interface([\n  \"function setAddr(bytes32 node, address a)\",\n  \"error StorageHandledByL2(uint256 chainId, address contractAddress)\",\n]);\nconst resolver = new Contract(resolverAddress, iface, l1Signer);\n\ntry {\n  await resolver.setAddr.staticCall(node, newAddr);   // preflight\n  await (await resolver.setAddr(node, newAddr)).wait(); // stored on L1\n} catch (err: any) {\n  const parsed = iface.parseError(err.data);\n  if (parsed?.name !== \"StorageHandledByL2\") throw err;\n  const [chainId, target] = parsed.args;\n  const l2 = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(rpcFor(chainId)));\n  // resend the original calldata, unchanged, to the L2 handler\n  const data = iface.encodeFunctionData(\"setAddr\", [node, newAddr]);\n  await (await l2.sendTransaction({ to: target, data })).wait();\n}\n```\n\n同一转交的 Solidity 侧：\n\n```solidity\nerror StorageHandledByL2(uint256 chainId, address contractAddress);\n\nfunction setAddr(bytes32, address) external view {\n    revert StorageHandledByL2(l2ChainId, l2Resolver);\n}\n```\n\n## 需要注意\n\n- **状态：Stagnant。** 该提案没有最终确定。它所基于的 CCIP Read（[EIP-3668](/eip-3668/)）是 Final。\n- 客户端必须拒绝指回以太坊主网的转交，并且在 L2 转交中必须重用原始 calldata，以避免被骗去签署另一笔恶意交易。\n- 链下数据库写入包含用户的地址，并来自用户的 IP，这可能被用来给钱包做指纹识别。规范建议让用户可以选择链上存储，并让客户端库可以代理、加入允许列表或拦截这些请求。\n- 链下数据库不提供任何链上保证；信任完全取决于网关运营方。\n- 没有实现该协议的客户端只会看到一次回滚。\n"}}}
