ERC-831 · Stagnant · ERC · 2018-01-15
ERC-831: URI Format for Ethereum
Defines the general ethereum: URI container, with an optional use-case prefix such as pay-, so QR codes and links can open the user's wallet; specific formats like ERC-681 plug into it.
What problem does it solve?
URIs in QR codes, web pages, emails and chat messages are a simple way for unrelated apps to hand work to a user's wallet. EIP-67 introduced ethereum: links, but it tied the whole scheme to a single use case: sending a transaction.
While ERC-681 was refining payment requests, its authors needed a lighter container that would not lock ethereum: into one purpose. EIP-831 defines that container. Each use case gets its own prefix and its own ERC for the payload, and existing EIP-67 links keep working.
How it works
The grammar is short:
request = "eth" [ "ereum" ] ":" [ prefix "-" ] payload
prefix = STRING
payload = STRING
- The scheme may be
ethereum:or the short formeth:. prefixnames the use case, for examplepay. It is optional.- If there is no prefix,
pay-is assumed. In that case the payload must start with0x, and no prefix may start with0x. So a URI that begins with0xclearly has no prefix, which keeps EIP-67 style URIs valid. payloadis required. Its structure is defined by the ERC for that prefix, not by EIP-831. ERC-681 defines thepay-payload: a target address or ENS name, an optional chain ID, an optional function name and its parameters.
The open-ended prefix lets the scheme grow to new use cases without reserving ethereum: for the few that existed in 2018.
Sample code
Valid URIs under this container:
ethereum:0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359?value=2.014e18
ethereum:pay-0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359?value=2.014e18
ethereum:pay-0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359@1?value=1e16
The first two mean the same thing, because pay- is the default.
A small parser that splits a URI into prefix and payload (TypeScript):
function parseEthereumUri(uri: string) {
const m = /^eth(?:ereum)?:(.+)$/i.exec(uri);
if (!m) throw new Error("not an ethereum URI");
const rest = m[1];
if (rest.startsWith("0x")) return { prefix: "pay", payload: rest };
const dash = rest.indexOf("-");
if (dash < 1) throw new Error("missing prefix or payload");
return { prefix: rest.slice(0, dash), payload: rest.slice(dash + 1) };
}
parseEthereumUri("ethereum:pay-0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359?value=1e18");
// { prefix: "pay", payload: "0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359?value=1e18" }
Things to know
- This proposal is Stagnant. The
pay-payload format it points to, ERC-681, is Final and uses the sameethereum:/pay-scheme. - Older EIP-67 parsers may fail on URIs that use a prefix. The spec accepts this as the cost of extensibility.
- The spec does not register any prefixes other than
pay. A new use case needs its own ERC. - URIs come from untrusted sources. A wallet should decode the request and show it clearly before the user signs.