EIPs Explained

ERC-6944 · Draft · ERC · 2023-04-27

ERC-6944: ERC-5219 Resolve Mode

Draft ERC that adds a "5219" resolve mode to web3:// URLs, so a contract can serve web resources through the ERC-5219 HTTP-like request interface.

What problem does it solve?

ERC-4804 defines web3:// URLs that map a URL to a read-only call on a contract, so front-ends can be served straight from the chain. A contract chooses how its URLs are interpreted via a resolveMode() function: auto (the path is parsed into an ABI function call) or manual (the raw path and query are passed as calldata).

ERC-5219 separately defines a contract interface for HTTP-like requests: the contract receives a resource path and parameters and returns a status code, body and headers. That shape is a natural fit for serving web pages, but web3:// clients had no way to know a contract speaks ERC-5219. ERC-6944 adds that missing link: a third resolve mode.

How it works

A contract that wants web3:// requests routed through ERC-5219 implements the ERC-5219 interface (IDecentralizedApp) and also:

function resolveMode() external pure returns (bytes32 mode);

returning the ASCII string "5219", right-padded to 32 bytes (0x3532313900…00). The comparison is case-insensitive.

A web3:// client calls resolveMode() on the target contract first:

  • "auto" (or no resolveMode at all) → ERC-4804 auto mode.
  • "manual" → ERC-4804 manual mode.
  • "5219" → translate the URL into an ERC-5219 request and render the returned status, headers and body like an HTTP response.

ERC-165 is deliberately not used; calling resolveMode is enough to check support.

Sample code

Declaring the mode in a contract:

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;

abstract contract ERC5219Resolver /* is IDecentralizedApp */ {
    function resolveMode() public pure returns (bytes32 mode) {
        return "5219"; // 0x35323139 followed by 28 zero bytes
    }
}

Checking a contract's mode from a client (ethers v6):

import { Contract, decodeBytes32String } from "ethers";

const c = new Contract(target, ["function resolveMode() view returns (bytes32)"], provider);
let mode = "auto";
try { mode = decodeBytes32String(await c.resolveMode()).toLowerCase(); } catch {}
// "5219" -> send an ERC-5219 request; otherwise use ERC-4804 auto/manual rules

Things to know

  • Status: Draft. Browser and gateway support depends on the web3:// client you use.
  • The security considerations of both ERC-4804 and ERC-5219 apply; content served from a contract is only as trustworthy as that contract and whoever can change it.
  • The web3:// URL spec has a newer draft revision, ERC-6860, and ERC-7618 adds content encoding for responses in this 5219 mode.

#web3-url #dapp #hosting #resolve-mode #erc5219

Details

Authors
Gavin John (@Pandapip1), Qi Zhou (@qizhou)
Status
Draft
Type
Standards Track / ERC
Created
2023-04-27
Requires
Required by

Machine-readable: Markdown · JSON