JavaScript theorytheory 0/50 · 0%
Web3 · medium

38. Working with wallet providers

EIP-1193, accounts and chain switching.

An injected wallet exposes `window.ethereum` with `request({ method, params })` and events such as `accountsChanged` and `chainChanged`. Requesting accounts triggers the connect prompt.

const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });
window.ethereum.on("chainChanged", () => location.reload());

Never auto-connect on page load without user intent, and always re-read the chain id before a write.

Check your understanding

  1. 1. Which method prompts a connection?

  2. 2. Which event fires when the network changes?

  3. 3. What is the standard for this interface?