Skip to content

Migrate MetaMask Connector to use new SDK (MMConnect)#2326

Merged
tanguyenvn merged 39 commits intoWeb3Auth:feat/metamask-connectfrom
adonesky1:ad/migrate-metamask-connector
Apr 13, 2026
Merged

Migrate MetaMask Connector to use new SDK (MMConnect)#2326
tanguyenvn merged 39 commits intoWeb3Auth:feat/metamask-connectfrom
adonesky1:ad/migrate-metamask-connector

Conversation

@adonesky1
Copy link
Copy Markdown

@adonesky1 adonesky1 commented Jan 7, 2026

Summary

  • Migrate MetaMask integration from @metamask/sdk to @metamask/connect-evm for improved connection handling
  • Refactor MetaMaskConnector to use the new SDK's createEVMClient() API with built-in event handlers and automatic chain management
  • Remove manual chain addition logic as the new SDK handles this internally during switchChain()
  • Update connector settings interface to align with the new SDK's configuration options

Videos

Extension:
https://drive.google.com/file/d/1r_lDBvwHWQhP-J4yFfqVHsqRR7bIS6Z1/view?usp=sharing

Mobile (native browser):
https://drive.google.com/file/d/1XECLgCOqa9VEeIK4gp1nUf0cs6RRg2V1/view?usp=sharing


Note

Medium Risk
Replaces the MetaMask connection stack and chain switching flow, which can affect wallet connection/rehydration behavior across EVM and Solana. Also adds new auth-token signing paths via EVM personal_sign and Solana wallet-standard signing, which may break login/authorization if provider behaviors differ.

Overview
Migrates the MetaMaskConnector from @metamask/sdk to the MetaMask Connect stack (@metamask/connect-multichain, @metamask/connect-evm, @metamask/connect-solana), changing it to a multichain connector that can surface both an EVM provider and a Solana wallet from one connection.

Updates initialization/connection/disconnection to use the multichain client (including display_uri handling for QR flows), revises connector configuration to a new MetaMaskConnectorSettings shape (dapp, ui, debug), and changes switchChain to use the new EVM client (dropping the old manual add-chain logic and disallowing switchChain when multiple namespaces are configured).

Adds a connector-level getAuthTokenInfo() implementation that creates a challenge and signs it via EVM personal_sign or Solana walletSignMessage depending on the active chain.

Demo/package updates: adjusts no-modal dependencies and lockfiles accordingly, tweaks noModal.ts to pass ui.headless, and enables server.host in the Vue demo Vite config.

Reviewed by Cursor Bugbot for commit 8e26a9a. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 7, 2026

@adonesky1 is attempting to deploy a commit to the Consensys Team on Vercel.

A member of the Team first needs to authorize it.

@adonesky1 adonesky1 marked this pull request as draft January 7, 2026 23:03
this.metamaskInstance = await this.metamaskPromise;
// TODO: Remove this hack
// Hack to ensure the ConnectEvm instance has fully resumed the connection
await new Promise((resolve) => setTimeout(resolve, 2000));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this awful delay to ensure that this async call in the ConnectEvm constructor has fully resolved. We need to fix this on the connect-monorepo side

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your understanding of how we resolve this on the connect-evm side of things?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to release connect-evm again, bump the version in web3auth, and then remove this setTimeout

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +226 to +229
// if (options.autoConnect) {
// this.rehydrated = false;
// this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, new Error("Failed to resume existing MetaMask Connect session.") as Web3AuthError);
// } else {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this commented code can be dropped?.. Not sure if it's more appropriate to throw an error if we fail to resume a previous session OR if we just say the connector is ready for new connections

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think it makes more sense to just say the connector is ready for new connections. But perhaps we should speak with @chaitanyapotti to see what patterns they recommend for their connectors

@jiexi
Copy link
Copy Markdown

jiexi commented Jan 20, 2026

Need: MetaMask/connect-monorepo#124

@adonesky1 adonesky1 changed the title Update metamask connector WIP Migrate MetaMask Connector to use new SDK (MMConnect) Jan 23, 2026
@adonesky1 adonesky1 marked this pull request as ready for review January 23, 2026 22:34
Comment on lines +34 to +48
/**
* Configuration options for the MetaMask connector using @metamask/connect-evm
*/
export interface MetaMaskConnectorSettings {
/** Dapp identification and branding settings */
dapp?: {
name?: string;
url?: string;
};
/** Enable debug logging for the MetaMask SDK */
debug?: boolean;
}

export interface MetaMaskConnectorOptions extends BaseConnectorSettings {
connectorSettings?: Partial<MetaMaskSDKOptions>;
connectorSettings?: MetaMaskConnectorSettings;
Copy link
Copy Markdown

@jiexi jiexi Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder to document this breaking change and include migration instructions where appropriate

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be undone before merge again

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be undone before merge again

jiexi added 2 commits March 16, 2026 15:44
…-connector

# Conflicts:
#	demo/react-app-no-modal/package-lock.json
#	demo/vue-app-new/package-lock.json
#	package-lock.json
#	packages/no-modal/package.json
#	packages/no-modal/src/connectors/metamask-connector/metamaskConnector.ts
@jiexi jiexi requested review from a team as code owners March 31, 2026 20:41
mode,
server: {
port: 8080,
host: true,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev server exposed on all network interfaces

Low Severity

host: true exposes the Vite dev server on all network interfaces (0.0.0.0), which is inconsistent with every other demo app in the repo. This was likely added temporarily to enable mobile device testing (the PR shows mobile browser testing videos) and appears to be one of the items @jiexi flagged as needing to be "undone before merge again."

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 60f3609. Configure here.

@tanguyenvn tanguyenvn changed the base branch from master to feat/metamask-connect April 13, 2026 16:54
@tanguyenvn tanguyenvn merged commit 595e646 into Web3Auth:feat/metamask-connect Apr 13, 2026
1 of 2 checks passed
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

There are 4 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 8e26a9a. Configure here.

} catch (error) {
this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, error as Web3AuthError);
initReject(WalletLoginError.connectionError("Failed to initialize MetaMask Connect SDK", error));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial init failure leaves connector falsely ready

High Severity

When createMultichainClient succeeds but createEVMClient or createSolanaClient throws, initReject rejects initializationPromise but execution continues past the catch block. Since this.multichainClient is non-null, the null guard at line 266 passes and the connector status is set to READY based on multichainClient.status. The connector now appears ready to consumers, but any call to connect() will always fail because ensureInitialized() awaits the already-rejected initializationPromise.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8e26a9a. Configure here.

// if (currentChainId !== chainId) {
// await this.switchChain(chainConfig, true);
// }
// }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented-out chain switching skips requested chain selection

Medium Severity

The EVM chain-switching logic after connect is entirely commented out. After connecting via the multichain client, the connector never switches to the chainId the caller requested. If the wallet is on a different EVM chain than expected, users will silently operate on the wrong chain.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8e26a9a. Configure here.

"node_modules/ox": {
"version": "0.11.3",
"resolved": "https://registry.npmjs.org/ox/-/ox-0.11.3.tgz",
"resolved": "https://consensys.jfrog.io/artifactory/api/npm/npm/ox/-/ox-0.11.3.tgz",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package lock resolves from private Artifactory registry

Medium Severity

Third-party packages ox, @adraffy/ens-normalize, and @noble/curves have their resolved URLs changed from the public npm registry to consensys.jfrog.io. This is a private Artifactory proxy that other contributors and CI won't have access to, and is flagged in the PR discussion as needing to be undone before merge.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8e26a9a. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants