EIPs Explained

EIP-6963 · Final · Interface · 2023-05-01

EIP-6963: Multi Injected Provider Discovery

Lets every installed browser wallet announce itself to a dapp through window events, so users can pick their wallet instead of whichever extension won the race for window.ethereum.

What problem does it solve?

Browser wallet extensions expose their EIP-1193 provider on one shared global, window.ethereum. Extensions load in unpredictable order, so with several wallets installed the last one to load usually wins, and some wallets deliberately delay injection to overwrite the others. Users can't reliably choose a wallet, and new wallets struggle because users effectively have to uninstall the incumbent.

EIP-6963 replaces the shared variable with an event-based handshake. Each wallet announces itself, the dapp collects all announcements, and the user chooses from a list.

How it works

Two window events form the protocol:

  • eip6963:announceProvider, a CustomEvent sent by a wallet. Its detail is a frozen { info, provider } object.
  • eip6963:requestProvider, a plain Event sent by the dapp, asking wallets to (re)announce.

A wallet must dispatch an announce event when it loads and listen for request events, answering each with another announce. A dapp must add its announce listener first, keep it for the page's lifetime, and then dispatch a request. Whichever side loads first, the dapp ends up with every wallet.

info (EIP6963ProviderInfo) contains:

Field Meaning
uuid UUIDv4 for this provider session, to tell announcements apart
name Human-readable wallet name
icon Data URI image (RFC 2397), at least 96×96px, square
rdns Reverse-DNS identifier, e.g. com.example.wallet, stable across sessions

Wallets should keep injecting window.ethereum for older dapps. Dapps should use 6963 discovery and fall back to window.ethereum only if no wallet announces.

Sample code

Dapp-side discovery with ethers v6:

import { BrowserProvider } from "ethers";

type Detail = { info: { uuid: string; name: string; icon: string; rdns: string }; provider: any };
const wallets = new Map<string, Detail>();

window.addEventListener("eip6963:announceProvider", (e: Event) => {
  const { detail } = e as CustomEvent<Detail>;
  wallets.set(detail.info.uuid, detail);
  render();
});
window.dispatchEvent(new Event("eip6963:requestProvider"));

function render() {
  const list = document.getElementById("wallets")!;
  list.replaceChildren();
  for (const { info, provider } of wallets.values()) {
    const img = document.createElement("img"); // icons only via <img>
    img.src = info.icon;
    img.alt = info.name;
    img.onclick = async () => {
      const signer = await new BrowserProvider(provider).getSigner();
      console.log(info.rdns, await signer.getAddress());
    };
    list.append(img);
  }
}

Wallet side, in short:

const announce = () =>
  window.dispatchEvent(new CustomEvent("eip6963:announceProvider", {
    detail: Object.freeze({ info, provider }),
  }));
window.addEventListener("eip6963:requestProvider", announce);
announce();

Things to know

  • Status: Final. It succeeded the earlier ERC-5749 window.evmproviders idea, and wallet connection libraries widely support it.
  • Render icons only through <img>. SVG can contain scripts that would run in the page.
  • rdns and name are self-reported and can be spoofed. Don't use them for feature detection or trust decisions without extra verification. Two announcements with the same uuid suggest tampering.
  • Wallets should Object.freeze the announced detail to stop other scripts from modifying it.
  • Because the dapp asks first, a wallet can wait for a request and ask the user's consent before revealing itself, which reduces fingerprinting.

#wallet #provider #browser #javascript #discovery

Details

Authors
Pedro Gomes (@pedrouid), Kosala Hemachandra (@kvhnuke), Richard Moore (@ricmoo), Gregory Markou (@GregTheGreek), Kyle Den Hartog (@kdenhartog), Glitch (@glitch-txs), Jake Moxey (@jxom), Pierre Bertet (@bpierre), Darryl Yeo (@darrylyeo), Yaroslav Sergievsky (@everdimension)
Status
Final
Type
Standards Track / Interface
Created
2023-05-01
Requires

Machine-readable: Markdown · JSON