index.d.ts 1.5 KB

12345678910111213141516171819202122232425262728293031
  1. interface MetaMaskEthereumProvider {
  2. isMetaMask?: boolean;
  3. once(eventName: string | symbol, listener: (...args: any[]) => void): this;
  4. on(eventName: string | symbol, listener: (...args: any[]) => void): this;
  5. off(eventName: string | symbol, listener: (...args: any[]) => void): this;
  6. addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
  7. removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
  8. removeAllListeners(event?: string | symbol): this;
  9. }
  10. export = detectEthereumProvider;
  11. /**
  12. * Returns a Promise that resolves to the value of window.ethereum if it is
  13. * set within the given timeout, or null.
  14. * The Promise will not reject, but an error will be thrown if invalid options
  15. * are provided.
  16. *
  17. * @param options - Options bag.
  18. * @param options.mustBeMetaMask - Whether to only look for MetaMask providers.
  19. * Default: false
  20. * @param options.silent - Whether to silence console errors. Does not affect
  21. * thrown errors. Default: false
  22. * @param options.timeout - Milliseconds to wait for 'ethereum#initialized' to
  23. * be dispatched. Default: 3000
  24. * @returns A Promise that resolves with the Provider if it is detected within
  25. * given timeout, otherwise null.
  26. */
  27. declare function detectEthereumProvider<T = MetaMaskEthereumProvider>({ mustBeMetaMask, silent, timeout, }?: {
  28. mustBeMetaMask?: boolean | undefined;
  29. silent?: boolean | undefined;
  30. timeout?: number | undefined;
  31. }): Promise<T | null>;