{"id":19525546,"url":"https://github.com/onekeyhq/detect-provider","last_synced_at":"2025-02-26T01:43:40.136Z","repository":{"id":40757214,"uuid":"397129876","full_name":"OneKeyHQ/detect-provider","owner":"OneKeyHQ","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-06T08:22:21.000Z","size":381,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-01-08T15:25:55.390Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/OneKeyHQ.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}},"created_at":"2021-08-17T06:17:53.000Z","updated_at":"2021-08-17T06:23:27.000Z","dependencies_parsed_at":"2023-02-08T04:01:56.596Z","dependency_job_id":null,"html_url":"https://github.com/OneKeyHQ/detect-provider","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneKeyHQ%2Fdetect-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneKeyHQ%2Fdetect-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneKeyHQ%2Fdetect-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneKeyHQ%2Fdetect-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OneKeyHQ","download_url":"https://codeload.github.com/OneKeyHQ/detect-provider/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240777555,"owners_count":19855856,"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-11T01:05:28.990Z","updated_at":"2025-02-26T01:43:40.097Z","avatar_url":"https://github.com/OneKeyHQ.png","language":"JavaScript","readme":"# @onekeyhq/detect-provider\n\nA tiny utility for detecting the OneKey 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 OneKey documentation](https://docs.onekey.so/guide/ethereum-provider.html) to learn how to use our provider.\n\n### Node.js\n\n```javascript\nimport detectEthereumProvider from '@onekeyhq/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 OneKey!', error)\n}\n```\n\n### HTML\n\n```html\n\u003cscript src=\"https://unpkg.com/@onekeyhq/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.mustBeOneKey`\n\nType: `boolean`\n\nDefault: `false`\n\nWhether `window.ethereum.isOneKey === 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 OneKey _extension_ provider is synchronously injected, while the OneKey _mobile_ provider is asynchronously injected.\n\nTo notify sites of asynchronous injection, OneKey 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":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonekeyhq%2Fdetect-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonekeyhq%2Fdetect-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonekeyhq%2Fdetect-provider/lists"}