Skip to content

feat: Add Multichain API to Flask #14756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 406 commits into from
May 20, 2025
Merged

Conversation

ffmcgee725
Copy link
Member

@ffmcgee725 ffmcgee725 commented Apr 21, 2025

Description

This branch adds support for the Multichain API to the Flask build of the Extension.

The existing API (via injected provider) should be completely unchanged.

(Very Briefly) What is the MetaMask Multichain API

  • Concurrent connection to any number of chains (no network switching)
  • Unified entry point for all chain ecosystems (EVM, BTC, Solana, Cosmos, Polkadot etc)
  • Accessible via window.postMessage(). Not accessible via an injected global like window.ethereum

Key Documents/Standards

mip = MetaMask Improvement Proposal

  • MIP-5 (Overview of the Multichain API)
    • CAIP-25 (new connection request API)
    • CAIP-27 (new request API, envelope with target scope/chainId included)
  • MIP-6 (Overview of how the Multichain API’s EVM support diverges from the 1193 injected provider)

Manual testing steps

(RECOMMENDED) Use the Multichain Test Dapp
NOTE: window.postMessage should be used as extensionId for mobile.

OR

yarn setup:flask

Then

yarn start:android:flask

or

yarn start:ios:flask

Setup event listener via dev tools

window.addEventListener('message', (event) => {
  const {
    target,
    data
  } = event.data;
  if (
    target !== "metamask-inpage" ||
    data?.name !== 'metamask-multichain-provider'
  ) {
    return;
  }
  console.log(data.data)
})

Send a multichain API request via dev tools

const caipPostMessage = (data) => {
  window.postMessage({
    target: 'metamask-contentscript',
    data: {
      name: 'metamask-multichain-provider',
      data
    }
  }, location.origin)
}

// create session
caipPostMessage({
    jsonrpc: '2.0',
    method: 'wallet_createSession',
    params: {
      optionalScopes: {}
    }
})

// get session
caipPostMessage({
    jsonrpc: '2.0',
    method: 'wallet_getSession',
    params: {}
})

// revoke session
caipPostMessage({
    jsonrpc: '2.0',
    method: 'wallet_revokeSession',
    params: {}
})

// invoke method
caipPostMessage({
    jsonrpc: '2.0',
    method: 'wallet_invokeMethod',
    params: {
            scope: 'eip155:1',
            request: {
                "method": "eth_blockNumber",
                "params": [],
            }
        }
})

More detailed example of manual requests

taken from extension equivalent Add Multichain API to Flask work

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

ffmcgee725 and others added 30 commits April 15, 2025 18:15
This reverts commit 1a42690.
@adonesky1 adonesky1 added Run Smoke E2E Requires smoke E2E testing and removed Run Smoke E2E Requires smoke E2E testing labels May 20, 2025
Copy link
Contributor

https://bitrise.io/ Bitrise

🔄🔄🔄 pr_smoke_e2e_pipeline started on Bitrise...🔄🔄🔄

Commit hash: 529a01b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/bbbb5e79-b60f-4656-8b0c-07c871e0fbd6

Note

  • This comment will auto-update when build completes
  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@metamaskbot
Copy link
Collaborator

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 529a01b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/bbbb5e79-b60f-4656-8b0c-07c871e0fbd6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

2 similar comments
@metamaskbot
Copy link
Collaborator

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 529a01b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/bbbb5e79-b60f-4656-8b0c-07c871e0fbd6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@metamaskbot
Copy link
Collaborator

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 529a01b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/bbbb5e79-b60f-4656-8b0c-07c871e0fbd6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
38.5% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@metamaskbot
Copy link
Collaborator

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 529a01b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/bbbb5e79-b60f-4656-8b0c-07c871e0fbd6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

2 similar comments
@metamaskbot
Copy link
Collaborator

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 529a01b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/bbbb5e79-b60f-4656-8b0c-07c871e0fbd6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@metamaskbot
Copy link
Collaborator

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 529a01b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/bbbb5e79-b60f-4656-8b0c-07c871e0fbd6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@adonesky1 adonesky1 added No E2E Smoke Needed If the PR does not need E2E smoke test run QA Passed QA testing has been completed and passed and removed QA in Progress QA has started on the feature. labels May 20, 2025
@metamaskbot
Copy link
Collaborator

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 529a01b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/bbbb5e79-b60f-4656-8b0c-07c871e0fbd6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@adonesky1 adonesky1 added No E2E Smoke Needed If the PR does not need E2E smoke test run and removed No E2E Smoke Needed If the PR does not need E2E smoke test run Run Smoke E2E Requires smoke E2E testing labels May 20, 2025
@adonesky1 adonesky1 added this pull request to the merge queue May 20, 2025
@metamaskbot
Copy link
Collaborator

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 529a01b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/bbbb5e79-b60f-4656-8b0c-07c871e0fbd6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

1 similar comment
@metamaskbot
Copy link
Collaborator

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 529a01b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/bbbb5e79-b60f-4656-8b0c-07c871e0fbd6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@Prithpal-Sooriya
Copy link
Contributor

Smoked skipped due to a flakey test with Notifications.
Validated that this should not block this PR

CC @MetaMask/notifications

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 20, 2025
@ffmcgee725 ffmcgee725 added this pull request to the merge queue May 20, 2025
Merged via the queue into main with commit ecbc9df May 20, 2025
55 of 62 checks passed
@ffmcgee725 ffmcgee725 deleted the feat/caip-multichain-migrate-core branch May 20, 2025 16:37
@github-actions github-actions bot locked and limited conversation to collaborators May 20, 2025
@metamaskbot metamaskbot added the release-7.48.0 Issue or pull request that will be included in release 7.48.0 label May 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
INVALID-PR-TEMPLATE PR's body doesn't match template No E2E Smoke Needed If the PR does not need E2E smoke test run QA Passed QA testing has been completed and passed release-7.48.0 Issue or pull request that will be included in release 7.48.0 skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-wallet-api-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.