Skip to main content

About the MetaMask APIs

MetaMask supports 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.

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.

Use MetaMask SDK with the provider API

You can call the provider API from a dapp without MetaMask SDK installed, but we recommend using the SDK to enable users to easily connect to the MetaMask browser extension and MetaMask Mobile. The SDK supports multiple dapp platforms including mobile and gaming dapps.

Get started by setting up the SDK.

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 playground. Methods in the API playground may have the following tags:

  • MetaMask - These methods behave in ways specific to MetaMask, and may or may not be supported by other wallets.
  • Restricted - These methods are restricted, which require requesting permission using wallet_requestPermissions.
  • Mobile - These methods are only available on MetaMask Mobile.
  • Ethereum API - These are standard Ethereum JSON-RPC API methods. See the Ethereum wiki for more information on these methods.
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).