Connecting to a Network via RPC
Remote Procedure Call (RPC) could be classified as a type of API (application programming interface) that allows for developers to run code that can be executed on servers remotely. In plain English, an RPC call is how a dApp communicates with the blockchain or accesses other information from remote servers. In this section, we will concern ourselves with RPC calls to the blockchain via Metamask to Ethereum testnets such as Rinkeby and RPC endpoint providers such as Infura, Alchemy, Chainstack, and Ankr.
Connecting to a Testnet with Metamask
When opening up the Metamask browser extension, we can connect to the various testnets by clicking on the pull-down menu as seen below and chose your desired testnet network:
If you are trying to view a given network’s RPC connection information or add a network, it can be accessed in the Metamask extension by clicking on the Hamburger(round multi-color icon above) > Settings > Networks. In my case, I am connected to the Ropsten testnet, so its Network Name, RPC URL, Chain ID, Currency Symbol, and Block Explorer URL are shown below:
Add a Network
A new network can be added in Metamask by clicking on the Add a network button and adding the 5 data inputs seen in the image above given in your tutorial or other source.
Connecting a dApp through an RPC Endpoint Provider
In blockchain development, it is necessary to connect your dApp to the blockchain to deploy smart contracts and interact with the deployed contract. This can be done by either running your own blockchain node such as GETH or accessing the blockchain through an RPC endpoint service such as Infura, Alchemy, Chainstack, Ankr, etc. Connecting through node providers is much easier than running your own node. By using a node provider, it is quick, easy and FREE to open an account and get access to RPC endpoints of many different testnets including Goerli Ethereum, Polygon Mumbai, Optimism Kovan and Solana Devnet. The websites for the aforementioned RPC endpoint providers can be found below:
- Infura: https://infura.io/ Click on the SIGN UP button.
- Alchemy: https://www.alchemy.com/ Click on Login, then Signup under the Login button.
- Chainstack: https://www.chainstack.com/ Click on the Start for free button.
- Ankr: https://www.ankr.com/ Click on Get a free endpoint, the Connect wallet to connect your Metamask wallet.
IT IS SUPER IMPORTANT TO ALWAYS DOUBLE-CHECK THE WEBSITE URL YOU ARE CLICKING ON AND THE POP-UP MESSAGE IN METAMASK WHEN CONNECTING YOUR WALLET. IF YOU ARE ON THE WRONG WEBSITE AND YOU ALLOW ACCESS TO YOUR METAMASK WALLET, YOU MAY BE ALLOWING HACKERS ACCESS TO YOUR WALLET. BE SAFE!! ALWAYS DOUBLE-CHECK!!