metamask-extension README

The project's README from github.com/MetaMask/metamask-extension. As one markdown file: README.md.

MetaMask Browser Extension

You can find the latest version of MetaMask on our official website. For help using MetaMask, visit our User Support Site.

For general questions, feature requests, or developer questions, visit our Community Forum.

MetaMask supports Firefox, Google Chrome, and Chromium-based browsers. We recommend using the latest available browser version.

For up to the minute news, follow us on X.

To learn how to develop MetaMask-compatible applications, visit our Developer Docs.

To learn how to contribute to the MetaMask codebase, visit our Contributor Docs.

To learn how to contribute to the MetaMask Extension project itself, visit our Extension Docs.

GitHub Codespaces quickstart

As an alternative to building on your local machine, there is a new option to get a development environment up and running in less than 5 minutes by using GitHub Codespaces. Please note that there is a Limited Free Monthly Quota, and after that GitHub will start charging you.

Note: You are billed for both time spent running, and for storage used

Open in GitHub Codespaces

  1. Start by clicking the button above
  2. A new browser tab will open with a remote version of Visual Studio Code (this will take a few minutes to load)
  3. A "Simple Browser" will open inside the browser with noVNC -- click Connect
    • Optional steps:
      • Click the button at the upper-right of the Simple Browser tab to open the noVNC window in its own tab
      • Open the noVNC sidebar on the left, click the gear icon, change the Scaling Mode to Remote Resizing
  4. Wait about 20 extra seconds on the first launch, for the scripts to finish
  5. Right-click on the noVNC desktop to launch Chrome or Firefox with MetaMask pre-installed
  6. Change some code, then run yarn start to build in dev mode
  7. After a minute or two, it will finish building, and you can see your changes in the noVNC desktop

Tips to keep your Codespaces usage lower

Codespaces on a fork

If you are not a MetaMask Internal Developer, or are otherwise developing on a fork, the default Infura key will be on the Free Plan and have very limited requests per second. If you want to use your own Infura key, follow the .metamaskrc and INFURA_PROJECT_ID instructions in the section Building on your local machine.

Building on your local machine

AI Agent Skills (yarn skills)

AI coding agents (Cursor, Claude Code, Codex) consume shared skills from the MetaMask/skills repo, with an optional private overlay from Consensys/skills. Per ADR #57 this content is not committed here — yarn skills syncs it on demand into local-only paths under .cursor/, .claude/, and .agents/.

Zero-config setup:

yarn install # refreshes the MetaMask/skills cache via the shared `@metamask/skills` CLI
yarn skills  # syncs all default skills through the `metamask-skills sync` command

Optional local configuration:

cp .skills.local.example .skills.local
# edit .skills.local to set SKILLS_DOMAINS or override skills source paths
yarn skills --select                         # interactively pick domains
SKILLS_DOMAINS=perps,testing yarn skills      # one-off domain override

Use .skills.local for persistent skills configuration. Shell environment variables with the same names are supported for one-off or CI overrides and take precedence.

Skipping yarn skills is fine — it only affects agent tooling, not the app build. The repo uses the shared @metamask/skills package so sync/cache behavior stays uniform across MetaMask packages. To opt into best-effort regeneration during install/setup, set SKILLS_AUTO_UPDATE=1 in your shell or .skills.local.

Git Hooks

To get quick feedback from our shared code quality fitness functions before committing the code, you can install our git hooks with Husky.

$ yarn githooks:install

You can read more about them in our testing documentation.

If you are using VS Code and are unable to make commits from the source control sidebar due to a "command not found" error, try these steps from the Husky docs.

Contributing

Development builds

To start a development build (e.g. with logging and file watching) run yarn start.

Development build with wallet state

You can start a development build with a preloaded wallet state, by adding TEST_SRP='<insert SRP here>' and PASSWORD='<insert wallet password here>' to the .metamaskrc file. Then you have the following options:

  1. Start the wallet with the default fixture flags, by running yarn start:with-state.
  2. Check the list of available fixture flags, by running yarn start:with-state --help.
  3. Start the wallet with custom fixture flags, by running yarn start:with-state --FIXTURE_NAME=VALUE for example yarn start:with-state --withAccounts=100. You can pass as many flags as you want. The rest of the fixtures will take the default values.

Advanced Webpack builds

yarn start is backed by Webpack. You can also call yarn webpack directly for advanced build-system debugging; see the Webpack README for more information.

yarn start:lavamoat is not currently supported because Webpack watch mode does not support LavaMoat. For production-like LavaMoat verification, use yarn webpack:lavamoat:build or yarn build:test.

React and Redux DevTools

To use React or Redux DevTools you'll first need to set METAMASK_REACT_REDUX_DEVTOOLS to true in .metamaskrc.

To start the React DevTools, run yarn devtools:react with a development build installed in a browser. This will open in a separate window; no browser extension is required.

To start the Redux DevTools Extension:

Then run the command yarn devtools:redux with a development build installed in a browser. This will enable you to use the Redux DevTools extension to inspect MetaMask.

To create a development build and run both of these tools simultaneously, run yarn start:dev.

Test Dapp

This test site can be used to execute different user flows.

Running Unit Tests and Linting

Run unit tests and the linter with yarn test. To run just unit tests, run yarn test:unit.

You can run the linter by itself with yarn lint, and you can automatically fix some lint problems with yarn lint:fix. You can also run these two commands just on your local changes to save time with yarn lint:changed and yarn lint:changed:fix respectively.

For Jest debugging guide using Node.js, see docs/tests/jest.md.

Running E2E Tests

Our e2e test suite can be run on either Firefox or Chrome. Here's how to get started with e2e testing:

Preparing a Test Build

Before running e2e tests, ensure you've run yarn install to download dependencies. Next, you'll need a test build. You have 3 options:

  1. Use yarn download-builds --build-type test to quickly download and unzip test builds for Chrome and Firefox into the ./dist/ folder. This method is fast and convenient for standard testing.
  2. Create a custom production-like Webpack test build. This command allows you to generate test builds for various types, including:
    • yarn build:test for main build
    • yarn build:test:flask for flask build
    • yarn build:test:mv2 for mv2 build
  3. Start a Webpack test build with live changes: yarn start:test is particularly useful for development. It starts a test build that automatically recompiles application code upon changes. This option is ideal for iterative testing and development. This command also allows you to generate test builds for various types, including:
    • yarn start:test for main build
    • yarn start:test:flask for flask build
    • yarn start:test:mv2 for mv2 build

Note: The yarn start:test command has LavaMoat and Snow disabled for faster iteration. Use yarn build:test for production-like LavaMoat verification.

Running Tests

Once you have your test build ready, choose the browser for your e2e tests:

These scripts support additional options for debugging. Use --helpto see all available options.

Specs that have been migrated from Selenium to Playwright (*.pw.spec.ts, see test/e2e/playwright/README.md) run through their own runner:

One-time setup for the Playwright runner (per machine, and again whenever the Playwright version changes):

yarn                                        # installs the Playwright package
yarn playwright install chromium firefox   # downloads the browser binaries

Running a single e2e test

Single e2e tests can be run with yarn test:e2e:single test/e2e/tests/TEST_NAME.spec.js along with the options below.

  --browser           Set the browser to be used; specify 'chrome', 'firefox', 'all'
                      or leave unset to run on 'all' by default.
                                                          [string] [default: 'all']
  --debug             Run tests in debug mode, logging each driver interaction
                                                         [boolean] [default: true]
  --retries           Set how many times the test should be retried upon failure.
                                                              [number] [default: 0]
  --leave-running     Leaves the browser running after a test fails, along with
                      anything else that the test used (the local node, the
                      test dapp, etc.)                   [boolean] [default: false]
  --update-snapshot   Update E2E test snapshots
                                             [alias: -u] [boolean] [default: false]

For example, to run the account-details tests using Chrome, with debug logging and with the browser set to remain open upon failure, you would use: yarn test:e2e:single test/e2e/tests/account-menu/account-details.spec.js --browser=chrome --leave-running

For migrated Playwright specs, pass the spec path as a positional filter to the Playwright runner instead:

# Run a single spec
yarn test:e2e:playwright:chrome test/e2e/tests/settings/terms-of-use.pw.spec.ts

# Run headless
PLAYWRIGHT_HEADLESS=1 yarn test:e2e:playwright:chrome test/e2e/tests/settings/terms-of-use.pw.spec.ts

# Debug with the Playwright Inspector (step through each driver action)
PWDEBUG=1 yarn test:e2e:playwright:chrome test/e2e/tests/settings/terms-of-use.pw.spec.ts

Running E2E tests with feature flags

Feature flags used in tests fall into two categories: remote flags (runtime values fetched from client-config) and build-time flags (compile-time values set during the build). Use the workflow that matches the flag type.

Remote feature flags (runtime)

Remote flags are provided at runtime and should usually follow production defaults from the Feature Flag Registry. You do not need a custom build just to change a remote flag value for a test.

Use one of these test-time overrides:

For code examples and detailed guidelines, see Feature flags in E2E tests in contributor-docs.

Build-time feature flags (compile-time)

Build-time flags are set before running tests and require creating a test build with the flag enabled. Set the flag either in your local .metamaskrc file or as an environment variable prefix (e.g. MULTICHAIN=1 yarn build:test), then follow the steps in Preparing a Test Build to create and run the build.

Feature Flag Registry

The Feature Flag Registry is the central source of truth for all remote feature flags used in MetaMask Extension E2E tests. A CI check runs on every PR to verify that every remote flag reference in changed files exists in the registry. For background on how remote feature flags work in MetaMask, see the Remote Feature Flags contributor doc.

Registry entry format

Each entry in test/e2e/feature-flags/feature-flag-registry.ts has the following shape:

myNewFlag: {
  name: 'myNewFlag',
  type: FeatureFlagType.Remote,
  inProd: true,
  productionDefault: false,
  status: FeatureFlagStatus.Active,
},
Field Description
name Must match the object key exactly
type FeatureFlagType.Remote (fetched at runtime) or FeatureFlagType.Build (compile-time)
inProd Whether the flag currently exists in the production client-config API
productionDefault Any valid JSON value (Json type — boolean, number, string, null, object, or array)
status FeatureFlagStatus.Active or FeatureFlagStatus.Deprecated
Add a flag to the registry

For the full process of creating a remote feature flag (LaunchDarkly setup, code integration), see the Remote Feature Flags contributor doc. Once the flag exists, register it for E2E tests:

  1. Look up the flag's current production value from the client-config API. If the flag is not yet in production, set inProd: false and productionDefault to the intended default.
  2. Add an entry to test/e2e/feature-flags/feature-flag-registry.ts in alphabetical order.
  3. If you access the flag via a constant (e.g. remoteFeatureFlags[MY_CONSTANT]), also add the constant mapping to .github/scripts/known-feature-flag-constants.mts so the CI check can resolve it.
Override flags in E2E tests

To test behavior with a flag value different from the production default, see the override examples in Remote feature flags (runtime) above.

The registry module also exports helper functions for use in tests and tooling (e.g. getProductionRemoteFlagApiResponse(), getProductionRemoteFlagDefaults()). See the JSDoc in feature-flag-registry.ts for details.

Remove a flag

When a remote feature flag is fully rolled out or no longer needed:

  1. Remove all references to the flag from application code (app/, ui/, shared/).
  2. Either remove the entry from the registry, or change its status to FeatureFlagStatus.Deprecated if you want to track it temporarily.
  3. The CI check will post a warning on PRs that remove the last codebase reference to a registered flag, reminding you to clean up the registry.

Running E2E performance benchmarks

E2E performance benchmarks measure flow timings (onboarding, send, swap, asset details, etc.) and can be run locally or in CI. Use yarn test:e2e:benchmark with --preset <name> or a file path. See test/e2e/benchmarks/flows/README.md for presets and options.

Running specific builds types e2e test

Different build types have different e2e tests sets. In order to run them look in the package.json file. You will find:

    "test:e2e:chrome:snaps": "SELENIUM_BROWSER=chrome node test/e2e/run-all.js --snaps",
    "test:e2e:firefox": "SELENIUM_BROWSER=firefox node test/e2e/run-all.js",

Test and iterate on GitHub Actions more quickly

Running the full workflow on GitHub Actions can take 30 minutes or more, but there are ways to speed it up for faster iteration

Changing dependencies

Whenever you change dependencies (adding, removing, or updating, either in package.json or yarn.lock), there are various files that must be kept up-to-date.

attribution.txt is generated by the release process. Do not generate it or commit and push changes to it in PRs, including dependency updates.

Architecture

Architecture Diagram

Other Docs

Dapp Developer Resources

metamask-extension (MetaMask/metamask-extension)

Searching Database…

这是什么?MetaMask 是一款浏览器扩展程序,让你可以直接在浏览器中访问和使用以太坊区块链上的网站(去中心化应用,即 dapp),它同时充当加密钱包和 Web3 入口。
这是独立应用还是浏览器扩展?它是一款浏览器扩展程序(而不是独立的桌面应用),可以安装到 Chrome、Firefox 或其他基于 Chromium 的浏览器中。
我怎么从源代码运行它来做开发?安装 Node.js 24(或使用 nvm),启用 Corepack,将 .metamaskrc.dist 复制为 .metamaskrc,添加你自己的 Infura API 密钥,运行 yarn install,然后用 yarn dist(Chromium)或 yarn dist:mv2(Firefox)进行构建;如需开发版本,也可以使用 yarn start。
我能不能直接用 GitHub Codespaces,而不在本地构建?可以。Codespaces 通过带有 noVNC 的远程 VS Code 为你提供可用的开发环境,不到 5 分钟即可就绪,但运行时长和存储的每月免费额度有限,超出部分需要付费。
这是给谁用的?只给普通用户,还是也给开发去中心化应用的人?它面向想在以太坊去中心化应用中使用钱包的普通用户,也面向希望利用已发布的开发者文档开发兼容 MetaMask 应用的开发者。
它实际支持哪些浏览器?支持 Firefox、Google Chrome,以及其他基于 Chromium 的浏览器(Brave、Edge、Opera 也在项目主题标签中被列为支持)。
Cursor 或 Claude Code 这类 AI 编程助手能用这个仓库的共享工具吗?可以。运行 yarn skills 会把 MetaMask/skills 仓库中的共享 AI 助手技能同步到仅限本地的文件夹(如 .cursor/ 和 .claude/)中,不过跳过这一步不影响实际的应用构建。
怎样运行端到端测试?先构建测试版本(运行 yarn build:test,或用 yarn download-builds --build-type test 下载),然后运行 yarn test:e2e:chrome 或 yarn test:e2e:firefox;已迁移的测试用例通过单独的 Playwright 运行器执行。
我能为开发预先加载带有资金或账户的测试钱包吗?可以。在 .metamaskrc 中添加 TESTSRP 和 PASSWORD,然后运行 yarn start:with-state,还可以加上自定义的测试数据参数,例如 --withAccounts=100。
Creator
MetaMask
Size
1.5 GB
Stars
13.2K
Age
11y
Commits · 90 Days