EIP-2255 · Final · Interface · 2019-08-22
EIP-2255: Wallet Permissions System
Adds wallet_requestPermissions and wallet_getPermissions to the wallet provider API, so a dapp asks once for named permissions (like seeing your accounts) instead of triggering a prompt for every action.
What problem does it solve?
Wallets sit between untrusted websites and the user's keys. The safe default is to prompt for everything, but that makes onboarding a string of popups: reveal your address, switch network, sign a challenge, approve a token, send a transaction.
Web users know a better pattern from OAuth ("Sign in with ..."): one screen listing what the site wants, which the user can approve, reject, or narrow. EIP-2255 brings that model to wallets with a small, generic permissions API.
How it works
Two methods on the EIP-1193 provider:
wallet_requestPermissions takes one object mapping method names to caveat objects:
interface PermissionRequest {
[methodName: string]: { [caveatName: string]: any };
}
The wallet shows a prompt. If the user approves, it returns an array of { parentCapability, date? }. If the user rejects, it throws an error with code 4001 (user rejected, per EIP-1193).
wallet_getPermissions takes no parameters and returns the permissions the current site holds (empty by default):
interface Permission {
invoker: string; // origin of the dapp, e.g. "https://app.example"
parentCapability: string; // the permitted method, e.g. "eth_accounts"
caveats: { type: string; value: any }[]; // restrictions on that permission
}
Calls to a restricted method fail until the matching permission has been granted. Caveats let a permission be attenuated; for example, a site could ask only for accounts that support a given signing method, or the user could add an expiry.
Sample code
Asking for account access explicitly and checking what was granted (browser, EIP-1193 provider):
const provider = (window as any).ethereum;
try {
await provider.request({
method: "wallet_requestPermissions",
params: [{ eth_accounts: {} }],
});
} catch (err: any) {
if (err.code === 4001) console.log("User rejected the request");
else throw err;
}
const permissions = await provider.request({ method: "wallet_getPermissions" });
const hasAccounts = permissions.some((p: any) => p.parentCapability === "eth_accounts");
if (hasAccounts) {
const accounts = await provider.request({ method: "eth_accounts" });
console.log(accounts);
}
Things to know
- Status is Final. MetaMask supports both methods; other wallets vary, so feature-detect and fall back to
eth_requestAccounts. - The EIP defines the request and response shapes, not which permissions or caveats exist. Those are wallet-specific.
- When a wallet shows the site's icon, it should be careful about fetching arbitrary URLs (the spec warns about server-side request forgery).
- ERC-7715 (Draft) builds on this idea for richer, scoped permissions such as session keys. Related wallet RPCs include EIP-3085 and EIP-3326 for adding and switching chains.