Get ERC20 tokens owned by address
If you’re into cryptocurrency, you might want to use Chainbase API Get ERC20 token balances to build a simple wallet to check the balances! This API returns all ERC20 token balances that an address owns. You can also use this API to automate the process of checking your token balances, and save yourself a lot of time and effort.
Overview - Tools you need to work with Chainbase
- A free account at Chainbase with an API key.
- An IDE. Our examples are shown in JavaScript, you can use VS Code as your IDE for example.
- A known wallet address as your input.
Step 1: Set up a free account at Chainbase
To better leverage the ability that Chainbase provides, you can register here for a free account and access to different APIs and data cloud.
After logging into Chainbase, visit the dashboard to get an overview. Create a new project in the console and get an API key.
Step 2: Write script using Chainbase API
- Using
fetch
in JavaScript.
- Using
axios
in JavaScript. You need to installaxios
usingnpm install axios --save
in the terminal first.
Step 3: Print the ERC20 token balances
Chainbase API Get ERC20 token balances takes the chain id and wallet address as parameters, and returns all ERC20 token balances that this wallet owns. You can also specify a certain token by feeding an address in the contract_address
field.
To get data printed, run command node <filename>.js
in the terminal. In this case, the balances of some ERC20 tokens owned by Vitalik on Ethereum are as follows.
API Reference
If you want to know more details on the endpoint and optional parameters, check out:
Support
If you meet any trouble following the tutorial, feel free to reach out to us in our Discord to get 24/7 community support.