1 2 3 4 5 6 7 8 9 10 11 12
import { Provider } from 'ethereum-types'; export const getProvider = (): Provider => { const injectedWeb3 = (window as any).web3 || undefined; try { // Use MetaMask/Mist provider return injectedWeb3.currentProvider; } catch (err) { // Throws when user doesn't have MetaMask/Mist running throw new Error(`No injected web3 found: ${err}`); } };