This standard translates an RFC 2396 URI like web3://uniswap.eth/
to an EVM message such as:
EVMMessage {
To: 0xaabbccddee.... // where uniswap.eth's address registered at ENS
Calldata: 0x
...
}
Currently, reading data from Web3 generally relies on a translation done by a Web2 proxy to Web3 blockchain. The translation is mostly done by the proxies such as dApp websites/node service provider/etherscan, which are out of the control of users. The standard here aims to provide a simple way for Web2 users to directly access the content of Web3, especially on-chain Web contents such as SVG/HTML. Moreover, this standard enables interoperability with other standards already compatible with URIs, like SVG/HTML.
This specification only defines read-only (i.e. Solidity's view
functions) semantics. State modifying functions may be defined as a future extension.
A Web3 URL is in the following form
web3URL = web3Schema [userinfo "@"] contractName [":" chainid] path ["?" query]
web3Schema = [ "ethereum-web3://" | "eth-web3://" | "web3://" ]
contractName = address | [name "." [ subDomain0 "." ... ]] nsProviderSuffix
path = ["/" method ["/" argument_0 ["/" argument_1 ... ]]]
argument = [type "!"] value
query = "attribute_1=value_1 [ "&" attribute_2=value_2 ... ]
attribute = "returns" | "returnTypes" | other_attribute
where
web3://
or w3://
for short.Once the "To" address and chainid are determined, the protocol will check the resolver mode of contract by calling "resolveMode" method. The protocol currently supports two resolve modes:
The manual mode will not do any interpretation of path and query, and put path [ "?" query ] as the calldata of the message directly.
The auto mode is the default mode to resolve (also applies when the "resolveMode" method is unavailable in the target contract). In the auto mode, if path is empty, then the protocol will call the target contract with empty calldata. Otherwise, the calldata of the EVM message will use standard Solidity contract ABI, where
argument_i is the ith argument of the method. If type is specified, the value will be translated to the corresponding type. The protocol currently supports the basic types such as uint256, bytes32, address, bytes, and string. If type is not specified, then the type will be automatically detected using the following rule in a sequential way:
type="uint256", if value is numeric; or
[name "." [ subDomain0 "." ... ]] nsProviderSuffix
. In this case, the actual value of the argument will be obtained from nsProviderSuffix, e.g., eth. If nsProviderSuffix is not supported, an unsupported NS provider error will be returned. Note that if method does not exist, i.e., path is empty or "/", then the contract will be called with empty calldata.
web3://w3url.eth/
The protocol will find the address of w3url.eth from ENS in chainid 1 (Mainnet), and then the protocol will call the address with "From" = "0x..." and "Calldata" = "0x2F".
web3://cyberbrokers-meta.eth/renderBroker/9999
The protocol will find the address of cyberbrokers-meta.eth from ENS on chainid 1 (Mainnet), and then call the address with "To" = "0x..." and "Calldata" = "0x" + keccak("view(uint256)")[0:4] + abi.encode(uint256(9999))
.
web3://vitalikblog.eth:5/
The protocol will find the address of vitalikblog.eth from ENS on chainid 5 (Goerli), and then call the address with "From" = "0x..." and "Calldata" = "0x2F" with chainid = 5.
web3://0xe4ba0e245436b737468c206ab5c8f4950597ab7f:42170/
The protocol will call the address with "To" = "0x9e081Df45E0D167636DB9C61C7ce719A58d82E3b" and "Calldata" = "0x" with chainid = 42170 (Arbitrum Nova).
web3://0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/balanceOf/vitalik.eth?returns=(uint256)
The protocol will find the addresses of vitalik.eth from ENS on chainid 1 (Mainnet) and then call the method "balanceOf(address)" of the contract with the charles.eth's address. The returned data will be parsed as uint256 like [ "10000000000000" ]
.
web3://0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/balanceOf/vitalik.eth?returns=()
The protocol will find the address of vitalik.eth from ENS on chainid 1 (Mainnet) and then call the method "balanceOf(address)" of the address. The returned data will be parsed as raw bytes like ["0x000000000000000000000000000000000000000000000000000009184e72a000"]
.
The purpose of the proposal is to add a decentralized presentation layer for Ethereum. With the layer, we are able to render any web content (including HTML/CSS/JPG/PNG/SVG, etc) on-chain using human-readable URLs, and thus EVM can be served as decentralized Backend. The design of the standard is based on the following principles:
Human-readable. The Web3 URL should be easily recognized by human similar to Web2 URL (http://
). As a result, we support names from name services to replace address for better readability. In addition, instead of using calldata in hex, we use human-readable method + arguments and translate them to calldata for better readability.
Maximum-Compatible with HTTP-URL standard. The Web3 URL should be compatible with HTTP-URL standard including relative pathing, query, fragment, etc so that the support of existing HTTP-URL (e.g., by browser) can be easily extended to Web3 URL with minimal modification. This also means that existing Web2 users can easily migrate to Web3 with minimal extra knowledge of this standard.
Simple. Instead of providing explicit types in arguments, we use a "maximum likelihood" principle of auto-detecting the types of the arguments such as address, bytes32, and uint256. This could greatly minimize the length of URL, while avoiding confusion. In addition, explicit types are also supported to clear the confusion if necessary.
Flexible. The contract is able to override the encoding rule so that the contract has fine-control of understanding the actual Web resources that the users want to locate.
No security considerations were found.
Copyright and related rights waived via CC0.