Single API to Get Ethereum Token Balance
Recently, we have added a new GraphQL API to query the token balance for Ethereum and other smart contract chains such as Algorand, Celo, Binance smart chain.
Let’s see some examples of how to get the token balances for the Ethereum addresses.
Get all token balances for an Ethereum address
To get all the token balances associated with an address. Run the following query.
Run below queries here — graphql.bitquery.io
Query
{
ethereum {
address(address: {is: "0xc43db41aa6649ddda4ef0ef20fd4f16be43144f7"}) {
balances {
currency {
symbol
}
value
}
}
}
}
Get ETH and USDT balance for an Ethereum address
To get the balance of specific tokens, you need to pass the smart contract address of that token in the currency filter. However, for Etherum balance, just pass “Eth” as a parameter.
Query
{
ethereum {
address(address: {is: "0xc43db41aa6649ddda4ef0ef20fd4f16be43144f7"}) {
balances(currency: {in: ["ETH", "0xdac17f958d2ee523a2206206994597c13d831ec7"]}) {
currency {
symbol
}
value
}
}
}
}
Token balance for 2 Ethereum addresses
To get the token balances for multiple Ethereum addresses, you need to pass those addresses in address
filter.
{
ethereum {
address(address: {in: ["0xc43db41aa6649ddda4ef0ef20fd4f16be43144f7", "0xF92ED3c3926Ad83f88878243FAcFDa68e745E98f"]}) {
balances {
currency {
symbol
}
value
}
}
}
}
Balance with the transfer history of Ethereum address
If you also want the history of transfers with balances, you can use the following query.
{
ethereum {
address(address: {is: "0xF92ED3c3926Ad83f88878243FAcFDa68e745E98f"}) {
balances {
value
history {
block
timestamp
transferAmount
value
}
}
}
}
}
How to query balances and history till the block ( inclusive )
If you want transfer the history and balance of an address till a particular block, use the following query.
{
ethereum {
address(address: {is: "0xc43db41aa6649ddda4ef0ef20fd4f16be43144f7"}) {
address
balances(height: {lteq: 10814942}) {
currency {
symbol
address
name
decimals
}
value
history {
value
transferAmount
block
timestamp
}
}
}
}
}
If you face any problem or have any question about our GraphQL APIs, you can ask them on our Telegram channel.
Also Read:
Subscribe to our newsletter
Subscribe and never miss any updates related to our APIs, new developments & latest news etc. Our newsletter is sent once a week on Monday.