{"eip":7618,"title":"Content encoding in ERC-5219 mode Web3 URL","description":"In ERC-5219 resolve mode, add ability to decode a compressed resource before serving it to the client","authors":["Qi Zhou (@qizhou)","Nicolas Deschildre (@nand2)"],"status":"Draft","type":"Standards Track","category":"ERC","created":"2024-02-08","requires":[5219,6944],"discussionsTo":"https://ethereum-magicians.org/t/erc-5219-resolve-mode/14088","repo":"ERCs","label":"ERC-7618","officialUrl":"https://eips.ethereum.org/EIPS/eip-7618","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7618.md","url":"https://eips.huatuo.xyz/eip-7618/","tldr":{"en":"A Draft extension to web3:// URLs in ERC-5219 resolve mode: if a contract returns a Content-Encoding header (gzip or brotli) the client cannot handle, the protocol decompresses the data before serving it, so sites can store compressed assets on chain.","ja":"ERC-5219 の resolve モードにおける web3:// URL の拡張ドラフト。コントラクトがクライアントの扱えない Content-Encoding ヘッダー（gzip または brotli）を返した場合、プロトコルが配信前にデータを展開するため、サイトは圧縮したアセットをオンチェーンに保存できる。","ko":"ERC-5219 resolve 모드에서 web3:// URL을 확장하는 초안. 컨트랙트가 클라이언트가 처리할 수 없는 Content-Encoding 헤더(gzip 또는 brotli)를 반환하면 프로토콜이 제공 전에 데이터를 압축 해제하므로, 사이트가 압축된 에셋을 온체인에 저장할 수 있다.","zh":"对 ERC-5219 resolve 模式下 web3:// URL 的草案扩展：如果合约返回了客户端无法处理的 Content-Encoding 头（gzip 或 brotli），协议会在提供数据之前先将其解压，使网站可以把压缩后的资源存放在链上。"},"tags":["web3-url","web3","storage","compression","http"],"explainers":{"en":{"lang":"en","tldr":"A Draft extension to web3:// URLs in ERC-5219 resolve mode: if a contract returns a Content-Encoding header (gzip or brotli) the client cannot handle, the protocol decompresses the data before serving it, so sites can store compressed assets on chain.","tags":["web3-url","web3","storage","compression","http"],"related":[6860,6944,5219,7617,4804],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7618/","markdown":"## What problem does it solve?\n\n`web3://` URLs ([ERC-6860](/eip-6860/)) let a browser or gateway load a website straight from smart contracts. In the [ERC-6944](/eip-6944/) \"resolve mode\", a contract implementing [ERC-5219](/eip-5219/)'s `request()` returns a status code, a body and HTTP-style headers, much like a web server.\n\nOn-chain storage is expensive, so storing HTML, JavaScript and images compressed saves a lot of gas. But simply returning `Content-Encoding: gzip` is unsafe: the requesting client might not support that algorithm. Full HTTP-style negotiation (the client sends `Accept-Encoding`, the server picks) does not fit well either, because the contract would need to store several versions of every file.\n\nERC-7618 solves this by making the `web3://` protocol layer responsible for decompressing when needed.\n\n## How it works\n\n1. The contract stores the resource compressed once, and its `request()` returns the compressed bytes plus a `Content-Encoding` header (for example `br`).\n2. The `web3://` client or gateway compares that encoding with what the end client advertised in `Accept-Encoding`.\n3. If the end client supports it, the bytes can be passed through compressed.\n4. If it does not, or no `Accept-Encoding` was given, the protocol **must decode** the content itself and remove the `Content-Encoding` header before forwarding it.\n5. Protocol implementations must support `gzip` and `br` (brotli). Any other encoding that would need decoding results in an \"unsupported content encoding\" error.\n\nNo interface changes are needed: it reuses the existing ERC-5219 `request()` return value and the standard HTTP header name.\n\n## Sample code\n\nA contract serving a brotli-compressed page in resolve mode (simplified):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CompressedSite {\n    struct KeyValue { string key; string value; }\n\n    bytes private indexBr; // brotli-compressed index.html, uploaded by the owner\n\n    function resolveMode() external pure returns (bytes32) {\n        return \"5219\";\n    }\n\n    function request(string[] memory resource, KeyValue[] memory /* params */)\n        external view\n        returns (uint statusCode, string memory body, KeyValue[] memory headers)\n    {\n        if (resource.length == 0) {\n            headers = new KeyValue[](2);\n            headers[0] = KeyValue(\"Content-Type\", \"text/html\");\n            headers[1] = KeyValue(\"Content-Encoding\", \"br\");\n            return (200, string(indexBr), headers);\n        }\n        return (404, \"\", new KeyValue[](0));\n    }\n}\n```\n\nA client fetching `web3://\u003ccontract-address\u003e/` receives plain HTML if it does not accept `br`.\n\n## Things to know\n\n- **Status: Draft**, as are the related [ERC-6944](/eip-6944/) and [ERC-6860](/eip-6860/)-based extensions.\n- The proposal changes behaviour of `web3://` clients and gateways, not of the contracts; contracts only need to set the header correctly.\n- It combines naturally with [ERC-7617](/eip-7617/) (chunked responses) for large files.\n- Decompression happens off chain in the client, so it adds no gas cost; it only reduces on-chain storage size.\n"},"ja":{"lang":"ja","tldr":"ERC-5219 の resolve モードにおける web3:// URL の拡張ドラフト。コントラクトがクライアントの扱えない Content-Encoding ヘッダー（gzip または brotli）を返した場合、プロトコルが配信前にデータを展開するため、サイトは圧縮したアセットをオンチェーンに保存できる。","tags":["web3-url","web3","storage","compression","http"],"related":[6860,6944,5219,7617,4804],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7618/","markdown":"## 何を解決するのか\n\n`web3://` URL（[ERC-6860](/eip-6860/)）を使うと、ブラウザやゲートウェイがスマートコントラクトから直接ウェブサイトを読み込めます。[ERC-6944](/eip-6944/) の \"resolve モード\" では、[ERC-5219](/eip-5219/) の `request()` を実装したコントラクトが、ウェブサーバーのようにステータスコード、本文、HTTP 風のヘッダーを返します。\n\nオンチェーンのストレージは高価なので、HTML、JavaScript、画像を圧縮して保存すれば gas を大幅に節約できます。しかし、単に `Content-Encoding: gzip` を返すだけでは安全ではありません。リクエスト元のクライアントがそのアルゴリズムに対応していない可能性があるからです。HTTP 風の完全なネゴシエーション（クライアントが `Accept-Encoding` を送り、サーバーが選ぶ）も適しません。コントラクトがすべてのファイルについて複数のバージョンを保存する必要が出てくるためです。\n\nERC-7618 は、必要に応じて展開する責任を `web3://` のプロトコル層に持たせることで、これを解決します。\n\n## 仕組み\n\n1. コントラクトはリソースを 1 回だけ圧縮して保存し、`request()` は圧縮済みのバイト列と `Content-Encoding` ヘッダー（たとえば `br`）を返します。\n2. `web3://` のクライアントまたはゲートウェイは、そのエンコーディングを、エンドクライアントが `Accept-Encoding` で示したものと比較します。\n3. エンドクライアントが対応していれば、バイト列は圧縮されたまま通過させることができます。\n4. 対応していない場合、または `Accept-Encoding` が指定されていない場合は、プロトコルが自らコンテンツを **デコードしなければならず**、転送前に `Content-Encoding` ヘッダーを取り除きます。\n5. プロトコルの実装は `gzip` と `br`（brotli）に対応しなければなりません。それ以外のエンコーディングで、デコードが必要になるものは \"unsupported content encoding\" エラーになります。\n\nインターフェースの変更は不要です。既存の ERC-5219 の `request()` の戻り値と、標準の HTTP ヘッダー名を再利用します。\n\n## サンプルコード\n\nresolve モードで brotli 圧縮されたページを配信するコントラクト（簡略版）:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CompressedSite {\n    struct KeyValue { string key; string value; }\n\n    bytes private indexBr; // brotli-compressed index.html, uploaded by the owner\n\n    function resolveMode() external pure returns (bytes32) {\n        return \"5219\";\n    }\n\n    function request(string[] memory resource, KeyValue[] memory /* params */)\n        external view\n        returns (uint statusCode, string memory body, KeyValue[] memory headers)\n    {\n        if (resource.length == 0) {\n            headers = new KeyValue[](2);\n            headers[0] = KeyValue(\"Content-Type\", \"text/html\");\n            headers[1] = KeyValue(\"Content-Encoding\", \"br\");\n            return (200, string(indexBr), headers);\n        }\n        return (404, \"\", new KeyValue[](0));\n    }\n}\n```\n\n`web3://\u003ccontract-address\u003e/` を取得するクライアントが `br` に対応していなければ、プレーンな HTML を受け取ります。\n\n## 知っておくべきこと\n\n- **ステータス: Draft**。関連する [ERC-6944](/eip-6944/) や [ERC-6860](/eip-6860/) ベースの拡張も同様です。\n- この提案が変えるのは `web3://` クライアントとゲートウェイの挙動であり、コントラクトの挙動ではありません。コントラクトはヘッダーを正しく設定するだけで済みます。\n- 大きなファイルについては、[ERC-7617](/eip-7617/)（チャンク分割されたレスポンス）と自然に組み合わせられます。\n- 展開はクライアント側のオフチェーンで行われるため、gas コストは増えません。減るのはオンチェーンのストレージサイズだけです。\n"},"ko":{"lang":"ko","tldr":"ERC-5219 resolve 모드에서 web3:// URL을 확장하는 초안. 컨트랙트가 클라이언트가 처리할 수 없는 Content-Encoding 헤더(gzip 또는 brotli)를 반환하면 프로토콜이 제공 전에 데이터를 압축 해제하므로, 사이트가 압축된 에셋을 온체인에 저장할 수 있다.","tags":["web3-url","web3","storage","compression","http"],"related":[6860,6944,5219,7617,4804],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7618/","markdown":"## 어떤 문제를 해결하나요?\n\n`web3://` URL([ERC-6860](/eip-6860/))을 쓰면 브라우저나 게이트웨이가 스마트 컨트랙트에서 곧바로 웹사이트를 불러올 수 있습니다. [ERC-6944](/eip-6944/)의 \"resolve 모드\"에서는 [ERC-5219](/eip-5219/)의 `request()`를 구현한 컨트랙트가 웹 서버처럼 상태 코드, 본문, HTTP 스타일 헤더를 반환합니다.\n\n온체인 저장소는 비싸기 때문에 HTML, JavaScript, 이미지를 압축해 저장하면 gas를 크게 아낄 수 있습니다. 하지만 단순히 `Content-Encoding: gzip`을 반환하는 것은 안전하지 않습니다. 요청하는 클라이언트가 그 알고리즘을 지원하지 않을 수 있기 때문입니다. HTTP 스타일의 완전한 협상(클라이언트가 `Accept-Encoding`을 보내면 서버가 고름)도 잘 맞지 않습니다. 컨트랙트가 파일마다 여러 버전을 저장해야 하기 때문입니다.\n\nERC-7618은 필요할 때 압축 해제를 `web3://` 프로토콜 계층이 맡게 해서 이 문제를 해결합니다.\n\n## 어떻게 동작하나요?\n\n1. 컨트랙트는 리소스를 한 번만 압축해 저장하고, `request()`는 압축된 바이트와 `Content-Encoding` 헤더(예: `br`)를 반환합니다.\n2. `web3://` 클라이언트나 게이트웨이는 그 인코딩을 최종 클라이언트가 `Accept-Encoding`으로 알린 것과 비교합니다.\n3. 최종 클라이언트가 지원하면 바이트를 압축된 채로 그대로 전달할 수 있습니다.\n4. 지원하지 않거나 `Accept-Encoding`이 주어지지 않았다면, 프로토콜이 직접 콘텐츠를 **디코딩해야 하며** 전달하기 전에 `Content-Encoding` 헤더를 제거합니다.\n5. 프로토콜 구현은 `gzip`과 `br`(brotli)을 지원해야 합니다. 디코딩이 필요한 그 외의 인코딩은 \"unsupported content encoding\" 오류가 됩니다.\n\n인터페이스 변경은 필요 없습니다. 기존 ERC-5219 `request()`의 반환값과 표준 HTTP 헤더 이름을 그대로 재사용합니다.\n\n## 샘플 코드\n\nresolve 모드에서 brotli로 압축된 페이지를 제공하는 컨트랙트(단순화):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CompressedSite {\n    struct KeyValue { string key; string value; }\n\n    bytes private indexBr; // brotli-compressed index.html, uploaded by the owner\n\n    function resolveMode() external pure returns (bytes32) {\n        return \"5219\";\n    }\n\n    function request(string[] memory resource, KeyValue[] memory /* params */)\n        external view\n        returns (uint statusCode, string memory body, KeyValue[] memory headers)\n    {\n        if (resource.length == 0) {\n            headers = new KeyValue[](2);\n            headers[0] = KeyValue(\"Content-Type\", \"text/html\");\n            headers[1] = KeyValue(\"Content-Encoding\", \"br\");\n            return (200, string(indexBr), headers);\n        }\n        return (404, \"\", new KeyValue[](0));\n    }\n}\n```\n\n`br`을 지원하지 않는 클라이언트가 `web3://\u003ccontract-address\u003e/`를 가져오면 일반 HTML을 받습니다.\n\n## 알아둘 점\n\n- **상태: Draft**이며, 관련된 [ERC-6944](/eip-6944/) 및 [ERC-6860](/eip-6860/) 기반 확장도 마찬가지입니다.\n- 이 제안이 바꾸는 것은 `web3://` 클라이언트와 게이트웨이의 동작이지 컨트랙트의 동작이 아닙니다. 컨트랙트는 헤더만 올바르게 설정하면 됩니다.\n- 큰 파일에는 [ERC-7617](/eip-7617/)(청크 응답)과 자연스럽게 결합됩니다.\n- 압축 해제는 클라이언트에서 오프체인으로 일어나므로 gas 비용이 추가되지 않으며, 온체인 저장 크기만 줄어듭니다.\n"},"zh":{"lang":"zh","tldr":"对 ERC-5219 resolve 模式下 web3:// URL 的草案扩展：如果合约返回了客户端无法处理的 Content-Encoding 头（gzip 或 brotli），协议会在提供数据之前先将其解压，使网站可以把压缩后的资源存放在链上。","tags":["web3-url","web3","storage","compression","http"],"related":[6860,6944,5219,7617,4804],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7618/","markdown":"## 它解决什么问题？\n\n`web3://` URL（[ERC-6860](/eip-6860/)）让浏览器或网关可以直接从智能合约加载网站。在 [ERC-6944](/eip-6944/) 的\"resolve 模式\"中，实现了 [ERC-5219](/eip-5219/) `request()` 的合约会像网页服务器一样返回状态码、正文和 HTTP 风格的头。\n\n链上存储很昂贵，所以把 HTML、JavaScript 和图片压缩后存储可以节省大量 gas。但是直接返回 `Content-Encoding: gzip` 并不安全：发起请求的客户端可能不支持该算法。完整的 HTTP 风格协商（客户端发送 `Accept-Encoding`，服务器选择）也不太合适，因为合约需要为每个文件存储多个版本。\n\nERC-7618 通过让 `web3://` 协议层在需要时负责解压来解决这个问题。\n\n## 它如何运作\n\n1. 合约把资源压缩后只存一份，其 `request()` 返回压缩后的字节以及一个 `Content-Encoding` 头（例如 `br`）。\n2. `web3://` 客户端或网关将该编码与终端客户端在 `Accept-Encoding` 中声明的编码进行比较。\n3. 如果终端客户端支持，字节可以保持压缩状态直接透传。\n4. 如果不支持，或者没有给出 `Accept-Encoding`，协议 **必须自行解码** 内容，并在转发之前移除 `Content-Encoding` 头。\n5. 协议实现必须支持 `gzip` 和 `br`（brotli）。任何其他需要解码的编码都会导致\"unsupported content encoding\"错误。\n\n无需修改接口：它复用现有 ERC-5219 `request()` 的返回值和标准的 HTTP 头名称。\n\n## 示例代码\n\n一个在 resolve 模式下提供 brotli 压缩页面的合约（简化版）：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CompressedSite {\n    struct KeyValue { string key; string value; }\n\n    bytes private indexBr; // brotli-compressed index.html, uploaded by the owner\n\n    function resolveMode() external pure returns (bytes32) {\n        return \"5219\";\n    }\n\n    function request(string[] memory resource, KeyValue[] memory /* params */)\n        external view\n        returns (uint statusCode, string memory body, KeyValue[] memory headers)\n    {\n        if (resource.length == 0) {\n            headers = new KeyValue[](2);\n            headers[0] = KeyValue(\"Content-Type\", \"text/html\");\n            headers[1] = KeyValue(\"Content-Encoding\", \"br\");\n            return (200, string(indexBr), headers);\n        }\n        return (404, \"\", new KeyValue[](0));\n    }\n}\n```\n\n如果客户端不接受 `br`，则请求 `web3://\u003ccontract-address\u003e/` 的客户端会收到纯 HTML。\n\n## 需要注意\n\n- **状态：Draft**，相关的 [ERC-6944](/eip-6944/) 以及基于 [ERC-6860](/eip-6860/) 的扩展也是如此。\n- 该提案改变的是 `web3://` 客户端和网关的行为，而不是合约的行为；合约只需要正确设置头。\n- 对于大文件，它可以与 [ERC-7617](/eip-7617/)（分块响应）自然结合。\n- 解压发生在客户端的链下，因此不增加 gas 成本；它只会减小链上存储的大小。\n"}}}
