3

I have a question : which provider should I choose for interacting with a contract on the mainnet and why ?

It seems like Web3Provider is easier to use, are there any drawbacks ?

Thank you for your answers.

1 Answer 1

10

To interact with the ethereum blockchain, you need to connect to a node. Most people don't bother setting up a node themselves so they connect to a third party node. In ethers.js a provider is basically your connection to the node. The type of provider you should use depends where your node is hosted.

If you are in a browser the most common way to connect to a node is to use the provider given by the browser extension MetaMask. The ethers documentation explains very simply how to connect to ethereum using MetaMask with the Web3Provider.

If you are using ethers elsewhere, it's more than likely that you will use the JsonRPCProvider. To use it, you only need the url given by the node provider. The docs have also explains clearly how to use the JsonRPCProvider.If you are looking for a free option to get started, I suggest you take a look at Infura.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.