Use ethers.js InfuraProvider or Web3Provider
In this tutorial, we'll create a simple React app to show the differences between using the ethers.js library's InfuraProvider
and Web3Provider
methods to send a transaction.
The key difference we'll highlight is that with Web3Provider you can load the private key from a Web3 wallet (MetaMask in this example), while InfuraProvider needs a wallet created locally with a stored private key.
This tutorial uses the Sepolia testnet.
Prerequisites
- Install MetaMask and create an Ethereum account for testing purposes.
- Load Sepolia ETH into your wallet from the Infura faucet.
- Node.js and NPM installed.
You can run the following to confirm that Node and NPM are installed:
node -v && npm -v
info
This tutorial was tested using ethers v5.7.2 and Node.js v16.17.0.