Difference between injected providers

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.

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.

1 Like