@metamask/detect-provider
Version:
A tiny utility for detecting the MetaMask Ethereum provider, or any EIP 1193-compliant provider.
32 lines (31 loc) • 1.5 kB
TypeScript
interface MetaMaskEthereumProvider {
isMetaMask?: boolean;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string | symbol): this;
}
export = detectEthereumProvider;
/**
* Returns a Promise that resolves to the value of window.ethereum if it is
* set within the given timeout, or null.
* The Promise will not reject, but an error will be thrown if invalid options
* are provided.
*
* @param options - Options bag.
* @param options.mustBeMetaMask - Whether to only look for MetaMask providers.
* Default: false
* @param options.silent - Whether to silence console errors. Does not affect
* thrown errors. Default: false
* @param options.timeout - Milliseconds to wait for 'ethereum#initialized' to
* be dispatched. Default: 3000
* @returns A Promise that resolves with the Provider if it is detected within
* given timeout, otherwise null.
*/
declare function detectEthereumProvider<T = MetaMaskEthereumProvider>({ mustBeMetaMask, silent, timeout, }?: {
mustBeMetaMask?: boolean | undefined;
silent?: boolean | undefined;
timeout?: number | undefined;
}): Promise<T | null>;