Web3 Primer
As can be seen from the official documentation, web3.js is a collection of libraries which allow you to interact with a local or remote ethereum node, using a HTTP or IPC connection.
There are a ton of things you can do with web3, but we'll be focusing on those directly related to interacting with a smart contract such as NGNT.
Connecting to an Ethereum Node
Ethereum nodes are also often called "clients".
Local Node
You can easily spin up a local node using Ganache. This is very useful for local development & testing.
Mainnet & Testnet (Rinkeby)
You can decide to host your own Mainnet or Rinkeby testnet node. There are open source clients like Geth, Trinity & Party (and a good amount more) that can be hosted on your own servers. These can all be configured to use the whichever network you want.
However, there are situations where one does not want to deal with the technical debt of running & maintaining their own nodes. There are a few "Ethereum clients as a service" platforms out there that take away all the stress & let you focus on building your application:
Etherscan: this is free but also rate limited. It should be used for applications that aren't making many requests and should not be relied on as an option to scale to many users & operations. The official introduction says "The Etherscan Ethereum Developer APIs are provided as a community service and without warranty, so please just use what you need and no more. We support both GET/POST requests and there is a rate limit of 5 calls per sec/IP."
Alchemy (recommended): Alchemy lets you pay-as-you-go to use their super reliable, fault tolerant clients to build your applications. Only potential drawback is that it's currently the most expensive option.
Infura: This is the most popular option. It has a decent free plan & while it might not be as reliable as Alchemy (for high volume/intensity users), it works great for most use cases.
Connecting to your Node/Client with web3
const Web3 = require('web3');
const Provider = Web3.providers.HttpProvider; // this could be a websocket provider
web3Provider = new Web3(new Provider(<url to Ethereum client>));
const provider = web3Provider.ethIt is with provider that we shall interact with & make function calls that help us receive and/or send NGNT in the next sections.
Last updated
Was this helpful?