Reading data from blockchain
When you access a blockchain explorer such as https://etherscan.io/, you will get the data such as the total supply or number of holders of a token. Some of the data can be retrieved directly from a smart contract by calling its functions. Some of the data such as historical transactions can be read from blocks. In this section, we will mainly focus on retrieving information by calling the smart contract function. To be more specific, we will add the total supply and current user balance on the UI shown in Figure 3.1. For how to read data from blocks, please refer to the ethers.js official documentation at https://docs.ethers.org/v5/api/providers/provider/ and check the getBlockWithTransactions function
.
The source code we are going to add is located in the src/frontend/features/TokenOperations/index.js
file. This is the main JavaScript file for the TOKEN OPERATIONS feature we’ll implement in the remaining sections of this chapter.
Before calling...