I found this image online but I can't tell the difference between metamask and an Ethereum provider. Also doesn't metamask use a provider to connect to the network? I'm confused
4 Answers
Yes, Metamask uses Infura in the background to connect to the network. So Metamask is a user interface on top of Infura service.
However, nothing forces you to use Metamask, it just happens to be handy for user interactions. But typically a dApp has also a separate backend connection to Ethereum: for example the backend needs to read token balances and present them for the user, so the backend uses a direct RPC connection to some Ethereum node (or to a node service provider, such as Infura).
So it all depends on your needs.
-
-
I'm actually trying to write about the different ways to connect to the blockchain and the advantages and disadvantages. so i would like to understand well what changes when i don't use metamask– MichealCommented Feb 8, 2021 at 10:44
As you probably know, the ethereum network comprises nodes
and each of these nodes has a copy of the blockchain. When we want to interact with the blockchain, we need to interact with one of these nodes.
The first thing that you would want to do if you want to talk to nodes is to specify which node to talk to. You can set up your own node or you could use one of the nodes by third-party services like Infura and Alchemy. These node that you connect with when you interact with the blockchain, whether you set it up yourself or used an existing one from services out there, are called providers
.
Once you connect to the blockchain through a provider you can read the state of the blockchain, but to change the state and write to the blockchain you would need to sign
messages. To sign messages you need keys
. Now if you are building a dApp, its probably not the best idea to store the users keys or ask them for it. This is where Metamask
comes in.
Metamask is a tool that handles this key management. On top of that it also provides a connection to the blockchain. This is because Metamask already has the connection to the nodes
provided by Infura. So to connect to the blockchain, all one has to do is ask MetaMask for the provider(one of the Infura nodes).
So to answer you question:
Provider
is the node that you use to interact with the blockchain.- Metamask is a tool that makes dApp development easy by handling key management and connecting the dApp with a provider.
See MetaMask documentation for more details.
I'm not an expert but I think these are the reasons you would use some other provide like infura or Alchemy.
- If the users browser does not have metamask installed then your website would not work.
- If the users metamask is connected to a different network than where your smart contract is, then you wont be able to access your smart contract.
So I use metamask only to get the address and to sign transactions, and use something else when I need to get data from the blockchain.
MetaMask knows private keys of the user and servers as the user interface when it comes to “private” RPC calls like sending or signing transactions. That’s the main difference between wallet’s provider and public RPC endpoints provided by infura / alchemy.
If you know private keys, you can also do all those calls with public endpoints though