---
eip: 7618
label: ERC-7618
title: Content encoding in ERC-5219 mode Web3 URL
status: Draft
type: Standards Track
category: ERC
created: 2024-02-08
requires: 5219, 6944
official: https://eips.ethereum.org/EIPS/eip-7618
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7618.md
canonical: https://eips.huatuo.xyz/eip-7618/
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]
---

# ERC-7618: Content encoding in ERC-5219 mode Web3 URL

> In ERC-5219 resolve mode, add ability to decode a compressed resource before serving it to the client

**TL;DR:** 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.

## What problem does it solve?

`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.

On-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.

ERC-7618 solves this by making the `web3://` protocol layer responsible for decompressing when needed.

## How it works

1. The contract stores the resource compressed once, and its `request()` returns the compressed bytes plus a `Content-Encoding` header (for example `br`).
2. The `web3://` client or gateway compares that encoding with what the end client advertised in `Accept-Encoding`.
3. If the end client supports it, the bytes can be passed through compressed.
4. 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.
5. Protocol implementations must support `gzip` and `br` (brotli). Any other encoding that would need decoding results in an "unsupported content encoding" error.

No interface changes are needed: it reuses the existing ERC-5219 `request()` return value and the standard HTTP header name.

## Sample code

A contract serving a brotli-compressed page in resolve mode (simplified):

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

contract CompressedSite {
    struct KeyValue { string key; string value; }

    bytes private indexBr; // brotli-compressed index.html, uploaded by the owner

    function resolveMode() external pure returns (bytes32) {
        return "5219";
    }

    function request(string[] memory resource, KeyValue[] memory /* params */)
        external view
        returns (uint statusCode, string memory body, KeyValue[] memory headers)
    {
        if (resource.length == 0) {
            headers = new KeyValue[](2);
            headers[0] = KeyValue("Content-Type", "text/html");
            headers[1] = KeyValue("Content-Encoding", "br");
            return (200, string(indexBr), headers);
        }
        return (404, "", new KeyValue[](0));
    }
}
```

A client fetching `web3://<contract-address>/` receives plain HTML if it does not accept `br`.

## Things to know

- **Status: Draft**, as are the related [ERC-6944](/eip-6944/) and [ERC-6860](/eip-6860/)-based extensions.
- The proposal changes behaviour of `web3://` clients and gateways, not of the contracts; contracts only need to set the header correctly.
- It combines naturally with [ERC-7617](/eip-7617/) (chunked responses) for large files.
- Decompression happens off chain in the client, so it adds no gas cost; it only reduces on-chain storage size.


---

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