{"id":18487076,"url":"https://github.com/MetaMask/detect-provider","last_synced_at":"2025-04-08T20:30:38.785Z","repository":{"id":38259263,"uuid":"262172814","full_name":"MetaMask/detect-provider","owner":"MetaMask","description":"A tiny utility for detecting the MetaMask Ethereum Provider, or any Provider compliant with EIP-1193.","archived":false,"fork":false,"pushed_at":"2024-04-11T12:56:17.000Z","size":1988,"stargazers_count":235,"open_issues_count":23,"forks_count":57,"subscribers_count":46,"default_branch":"main","last_synced_at":"2024-04-14T10:47:52.120Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MetaMask.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":"metamask","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-05-07T22:37:00.000Z","updated_at":"2024-06-18T12:26:06.013Z","dependencies_parsed_at":"2023-02-10T17:30:20.795Z","dependency_job_id":"266b46b5-a790-4d91-9b29-94865b962d13","html_url":"https://github.com/MetaMask/detect-provider","commit_stats":{"total_commits":52,"total_committers":12,"mean_commits":4.333333333333333,"dds":0.7115384615384616,"last_synced_commit":"9dc0085245a162ec7c5a856fefac4ce1eb334b70"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fdetect-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fdetect-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fdetect-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fdetect-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MetaMask","download_url":"https://codeload.github.com/MetaMask/detect-provider/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223343548,"owners_count":17129952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T12:50:12.167Z","updated_at":"2024-11-06T12:51:10.836Z","avatar_url":"https://github.com/MetaMask.png","language":"JavaScript","readme":"# @metamask/detect-provider\n\nA tiny utility for detecting the MetaMask Ethereum provider, or any provider injected at `window.ethereum`.\n\nIt has 0 dependencies and works out of the box in any modern browser, for synchronously and asynchronously injected providers.\n\n## Usage\n\nKeep in mind that the providers detected by this package may or may not support [the Ethereum JavaScript Provider API](https://eips.ethereum.org/EIPS/eip-1193).\nPlease consult [the MetaMask documentation](https://docs.metamask.io/guide/ethereum-provider.html) to learn how to use our provider.\n\n### Node.js\n\n```javascript\nimport { detectEthereumProvider } from '@metamask/detect-provider'\n\nconst provider = await detectEthereumProvider()\n\nif (provider) {\n\n  console.log('Ethereum successfully detected!')\n\n  // From now on, this should always be true:\n  // provider === window.ethereum\n\n  // Access the decentralized web!\n\n  // Legacy providers may only have ethereum.sendAsync\n  const chainId = await provider.request({\n    method: 'eth_chainId'\n  })\n} else {\n\n  // if the provider is not detected, detectEthereumProvider resolves to null\n  console.error('Please install MetaMask!')\n}\n```\n\n### HTML\n\n```html\n\u003cscript src=\"https://unpkg.com/@metamask/detect-provider/dist/detect-provider.min.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n  const provider = await detectEthereumProvider()\n\n  if (provider) {\n    // handle provider\n  } else {\n    // handle no provider\n  }\n\u003c/script\u003e\n```\n\n### Options\n\nThe exported function takes an optional `options` object.\nIf invalid options are provided, an error will be thrown.\nAll options have default values.\n\n#### `options.mustBeMetaMask`\n\nType: `boolean`\n\nDefault: `false`\n\nWhether `window.ethereum.isMetaMask === true` is required for the returned Promise to resolve.\n\n#### `options.silent`\n\nType: `boolean`\n\nDefault: `false`\n\nWhether error messages should be logged to the console.\nDoes not affect errors thrown due to invalid options.\n\n#### `options.timeout`\n\nType: `number`\n\nDefault: `3000`\n\nHow many milliseconds to wait for asynchronously injected providers.\n\n## Advanced Topics\n\n### Synchronous and Asynchronous Injection\n\nProviders can be either synchronously or asynchronously injected:\n\n- _Synchronously_ injected providers will be available by the time website code starts executing.\n- _Asynchronously_ injected providers may not become available until later in the page lifecycle.\n\nThe MetaMask _extension_ provider is synchronously injected, while the MetaMask _mobile_ provider is asynchronously injected.\n\nTo notify sites of asynchronous injection, MetaMask dispatches the `ethereum#initialized` event on `window` immediately after the provider has been set as `window.ethereum`.\nThis package relies on that event to detect asynchronous injection.\n\n### Overwriting or Modifying `window.ethereum`\n\nThe detected provider object returned by this package will strictly equal (`===`) `window.ethereum` for the entire page lifecycle, unless `window.ethereum` is overwritten.\nIn general, consumers should never overwrite `window.ethereum` or attempt to modify the provider object.\n\nIf, as a dapp developer, you notice that the provider returned by this package does not strictly equal `window.ethereum`, something is wrong.\nThis may happen, for example, if the user has multiple wallets installed.\nAfter confirming that your code and dependencies are not modifying or overwriting `window.ethereum`, you should ask the user to ensure that they only have a single provider-injecting wallet enabled at any one time.\n","funding_links":["https://opencollective.com/metamask"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMetaMask%2Fdetect-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMetaMask%2Fdetect-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMetaMask%2Fdetect-provider/lists"}