ERC-6860 · Draft · ERC · 2023-09-29
ERC-6860: Web3 URL to EVM Call Message Translation
Defines how a web3:// URL such as web3://uniswap.eth/ is turned into a read-only EVM call, so browsers and gateways can load on-chain HTML, SVG or JSON directly from contracts.
What problem does it solve?
To read on-chain data from a browser today you go through someone's website, RPC provider or block explorer, which translates for you. ERC-6860 lets a URL itself describe the contract call, so any compliant client or gateway can fetch content straight from the chain. A contract can then serve a whole web page (HTML, CSS, images, SVG) and be linked to like a normal site.
It is an updated version of ERC-4804, with a formal ABNF grammar, corrections and clarifications.
How it works
A URL has the shape:
web3://[from@]contractName[:chainId]/path?query#fragment
web3(orw3) is the scheme.fromoptionally sets the caller; default is0x0.contractNameis an address or a name, resolved via ENS (ENS, resolution rules in ERC-6821).chainIddefaults to the name service's chain (1 for.eth).- Only read-only (
view) calls are defined.
The client first calls resolveMode() on the contract:
- Manual mode (returns
"manual"as bytes32): the raw path and query are sent as calldata (an empty path becomes/, i.e.0x2f). The contract parses it itself and returns ABI-encodedbytes. MIME type istext/htmlunless the path ends in a file extension. Relative URLs work like HTTP. - Auto mode (returns
"auto", zero, or reverts): the path is/method/arg1/arg2..., ABI-encoded into a normal function call. Arguments can be typed (uint8!5,string!hello.svg) or auto-detected: digits →uint256, 32-byte hex →bytes32, 20-byte hex →address, other hex →bytes,true/false→bool, else a name to resolve to an address. - In auto mode,
?returns=(uint256,string)asks the client to decode the result to JSON (integers as0xhex, per JSON-RPC).?returns=()returns the raw bytes as hex in JSON. With noreturns, the result is treated as ABI-encodedbytes.
Sample code
Example URLs from the spec and what they call:
web3://w3url.eth/ # manual mode: calldata 0x2f, served as text/html
web3://cyberbrokers-meta.eth/renderBroker/9999
# auto mode: renderBroker(uint256 9999)
web3://0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/balanceOf/vitalik.eth?returns=(uint256)
# balanceOf(<vitalik.eth address>) -> ["0x..."] as application/json
A contract that serves pages in manual mode:
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;
contract Site {
function resolveMode() external pure returns (bytes32) {
return "manual";
}
// Any calldata that isn't resolveMode() lands here; it is the raw URL path.
fallback(bytes calldata path) external returns (bytes memory) {
if (keccak256(path) == keccak256("/")) {
return abi.encode(bytes("<html><body>Hello from the chain</body></html>"));
}
return abi.encode(bytes("Not found"));
}
}
Things to know
- Status is Draft. It supersedes ERC-4804's details (the
ethereum-web3://andeth-web3://schemes are dropped, more argument types are added, and integer results are hex rather than strings). - Browsers don't speak
web3://natively; you need a gateway, extension or dedicated client, and you trust it to make the call honestly unless it verifies results. - Auto-detected argument types can surprise you, e.g. a numeric-looking string becomes
uint256. Use explicittype!valuewhen it matters. - Large pages are bounded by what an
eth_callcan return under the node's gas limit for calls.