EIP-3091 · Stagnant · Interface · 2020-11-02
EIP-3091: Block Explorer API Routes
Standardizes four block explorer URL paths (/block, /tx, /address, /token) so wallets and dapps can link to any chain's explorer knowing only its base URL.
What problem does it solve?
Wallets and dapps constantly link out to block explorers: "view this transaction", "see this address". With one chain and one dominant explorer, hardcoding the URL format was fine. As more chains and layer-2 networks appeared, each explorer could choose its own paths, so a wallet adding a new network had to learn yet another URL scheme, and links broke or pointed to the wrong page.
EIP-3091 fixes that by agreeing on a common set of routes. If an explorer follows it, a wallet only needs the explorer's base URL.
How it works
Given a base URL such as https://explorer.example.org, a compliant explorer serves:
| Resource | Route |
|---|---|
| Block | <BLOCK_EXPLORER_URL>/block/<BLOCK_HASH_OR_HEIGHT> |
| Transaction | <BLOCK_EXPLORER_URL>/tx/<TX_HASH> |
| Account | <BLOCK_EXPLORER_URL>/address/<ACCOUNT_ADDRESS> |
| Token | <BLOCK_EXPLORER_URL>/token/<TOKEN_ADDRESS> |
The paths were picked to match what most explorers already used, so many were compliant from the start. An explorer with a different layout can comply by redirecting these paths to its own routes.
The base URL itself usually comes from chain metadata, for example the blockExplorerUrls field a dapp passes to wallet_addEthereumChain (EIP-3085).
Sample code
Building explorer links in TypeScript:
type Kind = "block" | "tx" | "address" | "token";
export function explorerLink(baseUrl: string, kind: Kind, id: string | number): string {
const base = baseUrl.replace(/\/+$/, ""); // strip trailing slash
return `${base}/${kind}/${id}`;
}
explorerLink("https://etherscan.io", "tx", "0xabc..."); // https://etherscan.io/tx/0xabc...
explorerLink("https://etherscan.io", "block", 19_000_000); // https://etherscan.io/block/19000000
explorerLink("https://etherscan.io/", "address", "0x1234..."); // https://etherscan.io/address/0x1234...
Using it with chain metadata a wallet already has:
const chain = { chainId: "0x1", blockExplorerUrls: ["https://etherscan.io"] };
window.open(explorerLink(chain.blockExplorerUrls[0], "tx", txHash));
Things to know
- Status: Stagnant. It was not finalized, but the four routes match the de facto convention used by many popular explorers.
- The EIP only defines web page routes for humans, not a data API. Explorers' JSON APIs are separate and still differ.
- Nothing forces an explorer to follow these paths, so wallets that support many networks may still need per-explorer exceptions.
- Block routes accept either a hash or a height; your code should pass whichever you have without assuming one.