Difference between injected providers


#1

There are many ways to detect injected provider (MetaMask, Mist, …). Some of them are Web3.givenProvider, web3.currentProvider and window.ethereum.

What is the difference between them? I know that window.ethereum uses EIP-1102, but what is the difference between the other two? Which one should I use?

I first asked this on Web3’s GitHub, but @nivida suggested to ask this here.


#2

The original provider is window.web3.currentProvider, but this came with the baggage of the web3.js framework. To reduce the amount of code injected in every page, every provider that is 1102 compatible should inject the same provider at window.ethereum.

You can fall back to the web3 one if you need to.

Sample code is available on the metamask docs site.