Skip to content

metaMask

Connector for MetaMask SDK.

Import

ts
import { metaMask } from 'wagmi/connectors'

Install

bash
pnpm add @metamask/connect-evm@~0.2.0
bash
npm install @metamask/connect-evm@~0.2.0
bash
yarn add @metamask/connect-evm@~0.2.0
bash
bun add @metamask/connect-evm@~0.2.0

Usage

ts
import { createConfig, http } from 'wagmi'
import { mainnet, sepolia } from 'wagmi/chains'
import { metaMask } from 'wagmi/connectors'

export const config = createConfig({
  chains: [mainnet, sepolia],
  connectors: [metaMask()],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Parameters

ts
import { type MetaMaskParameters } from 'wagmi/connectors'

Check out the MetaMask SDK docs for more info. A few options are omitted that Wagmi manages internally.

dapp

DappMetadata | undefined

Metadata is used to fill details for the UX on confirmation screens in MetaMask, including the following fields:

  • name: string - The name of the dapp.
  • url: string - URL of the dapp (defaults to window.location.origin).
  • iconUrl: string - URL to the dapp's favicon or icon.

Defaults to { name: window.location.hostname }.

ts
import { metaMask } from 'wagmi/connectors'

const connector = metaMask({
  dapp: { 
    name: 'My Wagmi App', 
    url: 'https://example.com', 
    iconUrl: 'https://example.com/favicon.ico', 
  }
})

debug

boolean | undefined

Enables debug mode for the MetaMask SDK. When enabled, provides additional logging and debugging information.

ts
import { metaMask } from 'wagmi/connectors'

const connector = metaMask({
  debug: true
})

connectAndSign

string | undefined

Shortcut to connect and sign a message in a single operation. When provided, the connector will connect to MetaMask and immediately prompt the user to sign the specified message.

This parameter is mutually exclusive with connectWith - only one can be used at a time.

ts
import { metaMask } from 'wagmi/connectors'

const connector = metaMask({
  connectAndSign: 'Sign this message to connect', 
})

connectWith

{ method: string; params: unknown[] } | undefined

Allows connecting with any RPC method. When provided, the connector will connect to MetaMask and immediately call the specified RPC method with the given parameters.

This parameter is mutually exclusive with connectAndSign - only one can be used at a time.

ts
import { metaMask } from 'wagmi/connectors'

const connector = metaMask({
  connectWith: { 
    method: 'eth_requestAccounts', 
    params: [], 
  }
})

Advanced

By default, if the EIP-6963 MetaMask injected provider is detected, this connector will replace it.

EIP-6963 defines a standard way for dapps to interact with multiple wallets simultaneously by injecting providers into the browser. Wallets that implement this standard can make their presence known to dapps in a consistent and predictable manner.

When MetaMask SDK detects an EIP-6963-compliant provider (such as MetaMask itself), the connector will automatically replace the default injected provider (like window.ethereum) with the one provided by MetaMask SDK.

See the rdns property for more information.

Released under the MIT License.