How do I get a list of my Ethereum ERC20 Tokens? — Tutorial Part 2
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 →
How do I #Buidl an Ethereum Lite Wallet? — Tutorial Part 1
Starting to learn blockchain development? Let’s building a simple wallet that reads current account balance and…
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:
- Token Balances — All tokens for an account
- Historical Token Balances — Previous token amounts held over time
- Token Transfers — Historical transactions for an account
Step 1: Get Current Token Balances
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!
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.
Step 3: Get Token Transfers
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.
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.