import { Duplex } from 'stream' ; import MetaMaskInpageProvider , { MetaMaskInpageProviderOptions , } from './MetaMaskInpageProvider' ; import shimWeb3 from './shimWeb3' ; interface InitializeProviderOptions extends MetaMaskInpageProviderOptions { /**
     * The stream used to connect to the wallet.
     */ connectionStream : Duplex ; /**
     * Whether the provider should be set as window.ethereum.
     */ shouldSetOnWindow ? : boolean ; /**
     * Whether the window.web3 shim should be set.
     */ shouldShimWeb3 ? : boolean ; } param options param options . connectionStream param options . jsonRpcStreamName param options . maxEventListeners param options . shouldSendMetadata param options . shouldSetOnWindow param options . shouldShimWeb3 returns export function initializeProvider ( { connectionStream , jsonRpcStreamName , logger = console , maxEventListeners = 100 , shouldSendMetadata = true , shouldSetOnWindow = true , shouldShimWeb3 = false , } ) { let provider = new MetaMaskInpageProvider ( connectionStream , { jsonRpcStreamName , logger , maxEventListeners , shouldSendMetadata , } ) ; provider = new Proxy ( provider , { deleteProperty : ( ) => true , } ) ; if ( shouldSetOnWindow ) { setGlobalProvider ( provider ) ; } if ( shouldShimWeb3 ) { shimWeb3 ( provider , logger ) ; } return provider ; } param providerInstance export function setGlobalProvider ( providerInstance ) { ( window as Record < string , any > ) . ethereum = providerInstance ; window . dispatchEvent ( new Event ( 'ethereum#initialized' ) ) ; }