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 wallet detection 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 to connect to MetaMask.

You can access the provider API using the selected EIP-6963 provider object. Throughout this documentation, we refer to the selected provider using provider.

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 request() 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 request() 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 request().

The RPC methods are divided into the following:

  • Restricted methods - Require user consent for actions that impact assets or data (for example, initiating a transaction).
  • Unrestricted methods - Allow dapps to perform basic actions without permission (for example, retrieving a public address).

Restricted methods

MetaMask implements permissions based on EIP-2255 to enhance security for when users interact with dapps. This requires that dapps obtain user consent before accessing certain features. Under the hood, permissions are plain, JSON-compatible objects, with fields that are mostly used internally by MetaMask.

Restricted methods are methods that cannot be called unless you have permission to do so using wallet_requestPermissions or wallet_requestSnaps.

The following methods are restricted:

Unrestricted methods

Unrestricted methods do not require requesting permission to call them, but they might require confirmation by the user (for example, wallet_addEthereumChain).