EIPs Explained

ERC-7617 · Draft · ERC · 2024-02-08

ERC-7617: Chunk support for ERC-5219 mode in Web3 URL

Adds a web3-next-chunk response header to ERC-5219-style web3:// contracts, so a large file can be served in pieces and streamed to the client instead of hitting the RPC gas limit.

What problem does it solve?

The web3:// URL scheme (ERC-6860, building on ERC-4804) lets a browser or gateway fetch web content straight from a smart contract using a read-only eth_call. In the ERC-5219 resolve mode (ERC-6944), the contract exposes an HTTP-like request() function that returns a status code, a body and headers.

Every eth_call is still bound by the RPC node's gas limit. A large image, script or video cannot be returned in a single call. ERC-7617 lets the contract split the response into chunks and tell the client where to find the next one.

How it works

  • The contract returns a normal response from request(). If more data follows, it adds a header web3-next-chunk whose value is a web3:// URL, either absolute or relative, pointing to the next chunk.
  • The client sends the status code, headers and first body to the user immediately, then starts streaming.
  • For each next-chunk URL, the client calls request() on the target contract, ignores its status code, appends its body to the stream, and repeats while a web3-next-chunk header is present.
  • If a URL is invalid, or its target contract does not use the ERC-5219 resolve mode, the stream ends with an error.

A header was chosen so the existing request() interface does not change. Because the value is a full URL, the next chunk can even come from a different contract.

Sample code

A contract serving a file stored as several chunks (Solidity):

struct KeyValue { string key; string value; }

contract ChunkedSite /* is IERC5219Resolver */ {
    string[] internal chunks; // filled by the owner

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

    function request(string[] memory resource, KeyValue[] memory params)
        external view returns (uint16 statusCode, string memory body, KeyValue[] memory headers)
    {
        uint256 i = params.length > 0 ? _parseUint(params[0].value) : 0; // ?chunk=i
        bool more = i + 1 < chunks.length;
        headers = new KeyValue[](more ? 2 : 1);
        headers[0] = KeyValue("Content-Type", "text/html");
        if (more) headers[1] = KeyValue("web3-next-chunk",
            string.concat("/index.html?chunk=", _toString(i + 1)));   // relative URL
        return (200, chunks[i], headers);
    }
    // _parseUint / _toString omitted
}

Things to know

  • Status: Draft, as are ERC-6860 and ERC-6944 it builds on.
  • The header is optional; clients that do not understand it will only show the first chunk, so put something sensible there.
  • Chunks are fetched one after another, so very large files mean many sequential eth_calls and slower loading.
  • Only the first response's status code and headers are used; later ones are ignored apart from web3-next-chunk.

#web3-url #web3 #hosting #http #onchain-website

Details

Authors
Qi Zhou (@qizhou), Nicolas Deschildre (@nand2)
Status
Draft
Type
Standards Track / ERC
Created
2024-02-08
Requires

Machine-readable: Markdown · JSON