EIP-1193 · Final · Interface · 2018-06-30
EIP-1193: Ethereum Provider JavaScript API
The standard JavaScript interface that browser wallets expose to web apps: one `request()` method plus a handful of events, so any dapp can talk to any wallet the same way.
What problem does it solve?
A web app (dapp) cannot sign transactions itself; it asks the user's wallet. Wallets do this by putting a JavaScript object, "the Provider", into the page. Early on every wallet shaped that object differently (send, sendAsync, enable, callbacks vs. promises), so dapps had to special-case each wallet.
EIP-1193 defines one minimal, promise-based, event-driven Provider API. Libraries such as ethers, web3.js and viem accept any EIP-1193 provider, and wallets such as MetaMask implement it.
How it works
One method:
interface RequestArguments {
readonly method: string;
readonly params?: readonly unknown[] | object;
}
provider.request(args: RequestArguments): Promise<unknown>;
The promise resolves with the RPC method's result or rejects with a ProviderRpcError ({ code, message, data? }). Standard error codes:
| Code | Meaning |
|---|---|
| 4001 | User rejected the request |
| 4100 | Method or account not authorised |
| 4200 | Method not supported |
| 4900 | Disconnected from all chains |
| 4901 | Not connected to the requested chain |
Five events via Node-style on / removeListener:
connectwith{ chainId }(hex string, as returned byeth_chainId, EIP-695)disconnectwith aProviderRpcErrorchainChangedwith the new hexchainIdaccountsChangedwith the neweth_accountsarraymessagefor anything else, e.g.eth_subscriptionnotifications
The spec is transport-agnostic: it says nothing about JSON-RPC over HTTP, and putting the provider at window.ethereum is a convention, not part of the standard.
Sample code
Raw provider usage in the browser:
const eth = (window as any).ethereum; // an EIP-1193 provider
try {
const accounts = await eth.request({ method: "eth_requestAccounts" });
const chainId = await eth.request({ method: "eth_chainId" });
console.log(accounts[0], parseInt(chainId, 16));
} catch (err: any) {
if (err.code === 4001) console.log("user said no");
else throw err;
}
eth.on("accountsChanged", (accounts: string[]) => console.log("now", accounts[0]));
eth.on("chainChanged", () => window.location.reload());
Wrapping it with ethers v6:
import { BrowserProvider, parseEther } from "ethers";
const provider = new BrowserProvider(window.ethereum); // accepts any EIP-1193 provider
const signer = await provider.getSigner();
await signer.sendTransaction({ to: recipient, value: parseEther("0.01") });
Things to know
- Accounts should not be exposed by default. Dapps request access explicitly with
eth_requestAccounts(EIP-1102) orwallet_requestPermissions(EIP-2255). - Treat the provider object as untrusted: any script on the page can read or overwrite it. Wallets must validate everything they receive.
- When several wallet extensions are installed they fight over
window.ethereum. EIP-6963 adds an event-based discovery mechanism so a dapp can list every injected provider. - Older wallets may still expose the legacy
send/sendAsync/enablemethods; the spec documents them in an appendix but new code should only userequest.