Skip to main content

About the Wallet API

MetaMask's Wallet API consists of an Ethereum provider API, which wraps a JSON-RPC API.

API documentation

The API methods are documented in the following references:

Ethereum provider API

MetaMask injects a global JavaScript API into websites visited by its users using the window.ethereum provider object. This API is specified by EIP-1193, and it allows dapps to request users' Ethereum accounts, read data from blockchains the user is connected to, suggest that the user sign messages and transactions, and more.

note

MetaMask supports EIP-6963, which introduces an alternative discovery mechanism to the window.ethereum injected provider. This alternative mechanism enables dapps to support wallet interoperability by discovering multiple injected wallet providers in a user's browser. We recommend using this mechanism for provider discovery.

The MetaMask Ethereum provider API contains the following:

  • Properties - The provider contains a property that detects if a user has MetaMask installed.
  • Methods - The provider contains methods that dapps can call. The window.ethereum.request(args) provider method wraps the JSON-RPC API; dapps can use this provider method to call any RPC method.
  • Events - The provider emits events that dapps can listen to.

View the provider API reference for all the provider properties, methods, and events.

JSON-RPC API

MetaMask uses the window.ethereum.request(args) method of the provider API to wrap a JSON-RPC API. The JSON-RPC API contains standard Ethereum JSON-RPC API methods and MetaMask-specific methods.

The RPC methods are documented in the interactive JSON-RPC API reference.

note

All RPC method requests can return errors. Make sure to handle errors for every call to window.ethereum.request(args).

Restricted methods

MetaMask introduced wallet permissions in EIP-2255. In this permissions system, each RPC method is restricted or unrestricted. If a method is restricted, a dapp must request permission to call it using wallet_requestPermissions. Under the hood, permissions are plain, JSON-compatible objects, with fields that are mostly used internally by MetaMask.

Outside of Snaps restricted methods, the only restricted method is eth_accounts, which allows you to access the user's Ethereum accounts. More restricted methods will be added in the future.

Unrestricted methods

Unrestricted methods do not require requesting permission to call them, but they might still rely on permissions to succeed (for example, the signing methods require calling the restricted eth_accounts method), or they might require confirmation by the user (for example, wallet_addEthereumChain).