Get Token Balance For Any ETH Address by using Smart Contracts in JS

Shmoji
Coinmonks

--

Hello, in this tutorial I will show you the simplest example possible for how to get any ERC20 token balance for any Ethereum address.

So that you know what you are getting into, the image below from ideamarket.io shows an example of the functionality you will learn how to build:

During this process, you will also learn how to use smart contracts in your frontend code since they are required to get ERC20 token balances.

Resources

Project Setup

To get started, create a basic Next.JS app. Create a src folder at the top of the project and move the pages and styles folders into it. Then, we’ll just continue creating everything in this src folder.

Go ahead and install all the required dependences. NPM works fine, but I use yarn, so the command to install everything is yarn add web3 @web3-react/core @web3-react/injected-connector bignumber.js

--

--