Created
February 28, 2018 08:46
-
-
Save jbutko/608c23e02662c5108c12a100220640e1 to your computer and use it in GitHub Desktop.
web3.js - get current provider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getProviderName = () => { | |
let providerName = "UNKNOWN" | |
if(window.web3.currentProvider.constructor.name === "MetamaskInpageProvider") | |
providerName = "METAMASK" | |
else if(window.web3.currentProvider.constructor.name === "EthereumProvider") | |
providerName = "MIST" | |
else if(window.web3.currentProvider.constructor.name === "o") | |
providerName = "PARITY" | |
else if(window.web3.currentProvider.host.indexOf("infura")!==-1) | |
providerName = "INFURA" | |
else if(window.web3.currentProvider.host.indexOf("localhost")!==-1) | |
providerName ="LOCALHOST" | |
return providerName | |
} | |
// via https://ethereum.stackexchange.com/questions/24266/elegant-way-to-detect-current-provider-int-web3-js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment