- An installed MetaMask browser extension, on desktop or inside the MetaMask in-app browser.
- A MetaMask SDK pairing URI rendered as a QR code on desktop.
- An SDK-managed handoff to MetaMask on mobile web or React Native.
MetaMask SDK pairing is not a generic WalletConnect connection. The MetaMask
functions open MetaMask on mobile. Use their returned URI only when rendering
a desktop QR code.
Prerequisites
- Create and initialize a Dynamic client.
- Enable EVM and/or Solana in the Dynamic developer console.
- Install
@dynamic-labs-sdk/evmand/or@dynamic-labs-sdk/solana. - On React Native, complete React Native setup.
Add the extensions
The MetaMask extensions in@dynamic-labs-sdk/evm/metamask and @dynamic-labs-sdk/solana/metamask cover only the desktop QR code and the mobile handoff. The installed MetaMask browser extension is discovered by the standard chain extensions through EIP-6963 (EVM) and Solana Wallet Standard, so add both:
- EVM
- Solana
Connect an installed extension
This route applies when MetaMask runs as a browser extension: a desktop browser with MetaMask installed, or your dapp opened inside the MetaMask in-app browser. On mobile web and React Native without the extension, use the URI routes below instead. Use the chain-specific key helper to detect a MetaMask provider announced through EIP-6963 or Solana Wallet Standard. If the helper returns a key, pass it to the normal wallet provider connection flow.getMetaMaskSolanaExtensionWalletProviderKey from @dynamic-labs-sdk/solana/metamask.
Connect with a MetaMask SDK URI
The URI functions return{ uri, approval }:
- On desktop, render
urias a QR code for the user to scan with MetaMask. - On mobile web and React Native, the SDK opens MetaMask. You do not need to use
uri. - Call
approval()after starting the connection. It resolves with{ walletAccounts }after the user finishes the wallet interactions.
The connect-only functions add an unverified wallet account by default. Pass
{ addToDynamicWalletAccounts: false } if you only need the returned account. The connect-and-verify functions verify the account before approval() resolves. Users may see separate pairing and verification requests in MetaMask. Each function returns one wallet account for its selected chain.
Desktop QR code
Render the URI with your QR code library. The user must scan the QR code from MetaMask.- EVM
- Solana
Mobile web
Call the MetaMask function from the user’s click or tap handler. The SDK opens MetaMask:React Native
React Native uses the same URI pairing functions. Call the function from the user’s press handler so the SDK can open MetaMask.- Expo
- Bare React Native
metadata.nativeLink and metadata.universalLink on your Dynamic client so MetaMask can return the user to your app. See React Native setup.
Route MetaMask from a wallet picker
CallgetWalletOptionsCatalogue({ includeMobileOptions: true }) to include MetaMask’s mobile and QR routes. A MetaMask entry can contain:
withWalletProviderfor the installed MetaMask browser extension.metamaskSdkUrifor MetaMask SDK desktop QR and mobile pairing.inAppBrowserfor opening your dapp inside MetaMask.
withWalletProvider option is the installed MetaMask browser extension, so connect it through the normal wallet provider flow.
See Build a Wallet Picker for inAppBrowser, installation, and fallback handling.
Common pitfalls
A fresh pairing replaces stale connection state
Each MetaMask URI function clears stale MetaMask pairing state before requesting a new URI. If pairing fails or expires, call the URI function again. Render its new URI only for a desktop QR code. Do not cache and reuse a previous URI.User rejection and timeouts
The initial URI function orapproval() can reject if the user cancels a wallet interaction. The URI function also rejects with MetaMaskDisplayUriMissingError if MetaMask does not provide a pairing URI, or NoAddressFoundError if the approved session has no account.
Keep the connection UI available so the user can retry, but allow only one attempt at a time. Disable retry while the URI request or approval() is pending.
MetaMask transport timeouts are not automatically retried. A timed-out signing or transaction request may still be pending in MetaMask. Avoid immediately sending the same fund-moving request again.
Related
- Build a Wallet Picker shows how to handle every connection option.
- Get Wallet Options Catalogue documents the wallet and connection option types.
- Authenticate with External Wallets covers installed wallet providers.
- Authenticate with WalletConnect covers non-MetaMask WalletConnect flows.