How do I get a list of my Ethereum ERC20 Tokens? — Tutorial Part 2

Trevor Clarke
Apr 2, 2019 · 3 min read

Continuing from last week’s blog about how to build your own wallet, adding ERC20 support!

TLDR; ERC20 Tokens are all the rage, but are they hard to add to your dApp? Not anymore! See this demo for your address →

If you haven’t already, check out last weeks Part 1! ❤️

Tutorial Part 2: Get ERC20 Balance & Transfers

We’re going to build updates to our wallet utilizing a few data sets:

  1. Token Balances — All tokens for an account
  2. Historical Token Balances — Previous token amounts held over time
  3. Token Transfers — Historical transactions for an account

If you haven’t already, get a Free Amberdata API Key:
Go to Amberdata.io, and click “Get Started” to get a Free Developer API Key. You will need this to access the data in the next steps.

Image for post
Image for post
View Current Token Balances

Step 1: Get Current Token Balances

Using Axios & Amberdata API it is easy to request an Ethereum address token balance. See the following snippet:

The response above returns current token holdings:
1. “address” — This is the contract address of the token.
2. “holder” —The address for the token holder
3. “amount” — The token amount the address owns. This is the balance amount the address owner can spend or HODL.

NOTE: You can also know if the token is an ERC20 or NFT based on the booleans for that token. If “isERC721” is true, then it is an NFT (non-fungible token) which could be utilizing digitally rare artwork like in opensea.io or clovers.network!

Image for post
Image for post
View Historical Token Balances

Step 2: Get Historical Token Balances

Most users want to see their balance over time. This is achieved using the historical holdings endpoint:

The response from the endpoint has a couple things to understand:
1. “metadata” — This contains developer context. In this example, “columns” returns the human readable naming for the keys/values in data array.
2. “data” — The array containing items where each item is a single day aggregation of the address token holdings.

You can use the data array to generate a chart like we did!
You could also use this data to understand the holdings for several addresses at once! Very helpful if you have a contract and want to understand historical usage of your contract.

Image for post
Image for post
Token Transfers for an Ethereum Address

Step 3: Get Token Transfers

Last important piece — token transfers allow users to understand the flow and balance change for their account. This is easily achieved in a similar request to address transactions, see this example:

The response has several important features:
1. “amount” — The token amount transferred either to or from this address
2. “decimals” — Represent the amount using decimals, to accurately annotate the balance.
3. “tokenAddress” — The token contract address, used with name & symbol you can easily represent the token in a human-readable fashion.

All Done!

Now you have a comprehensive wallet functionality you can add to your dApp or project! If you integrate, send us a link and we’ll showcase your integration!

This is just one of many ways to build using the Amberdata API. We’re constantly adding more tutorials! You can view all previous tutorials in our new website page here →

That’s it for this tutorial, share with colleagues, friends and on social!
We’d love to hear your thoughts in the comments below.

Previous Tutorials:

For more information about Amberdata.io:

amberdata

Amberdata is the leading data infrastructure for blockchain…

Trevor Clarke

Written by

VP of Product - Amberdata.io, Passionate Software Engineer 🤓, Hobbyist in 3D Design & Robotics

amberdata

amberdata

Amberdata is the leading data infrastructure for blockchain and digital assets. The API empowers our customer to build decentralized applications, backtest trading strategies, gain actionable insights and accelerate time to market for their digital asset and blockchain offering

Trevor Clarke

Written by

VP of Product - Amberdata.io, Passionate Software Engineer 🤓, Hobbyist in 3D Design & Robotics

amberdata

amberdata

Amberdata is the leading data infrastructure for blockchain and digital assets. The API empowers our customer to build decentralized applications, backtest trading strategies, gain actionable insights and accelerate time to market for their digital asset and blockchain offering

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store