âī¸ Token BalancesLearn how to fetch the ERC20/721/1155/POAP balances of a Solana address across Ethereum, Base, Degen Chain, and other Airstack-supported chains.
Table Of Contents
In this guide, you will learn how to use Airstack to:
Pre-requisites
Basic knowledge of GraphQL
Get Started
JavaScript/TypeScript/Python
If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:
npm yarn pnpm pip
React
Copy npm install @airstack/airstack-react
Node
Copy npm install @airstack/node
React
Copy yarn add @airstack/airstack-react
Node
Copy yarn add @airstack/node
React
Copy pnpm install @airstack/airstack-react
Node
Copy pnpm install @airstack/node
Then, add the following snippets to your code:
React Node Python
Copy import { init , useQuery } from "@airstack/airstack-react" ;
init ( "YOUR_AIRSTACK_API_KEY" );
const query = `YOUR_QUERY` ; // Replace with GraphQL Query
const Component = () => {
const { data , loading , error } = useQuery (query);
if (data) {
return < p >Data: { JSON .stringify (data)}</ p >;
}
if (loading) {
return < p >Loading...</ p >;
}
if (error) {
return < p >Error: { error .message}</ p >;
}
};
Copy import { init , fetchQuery } from "@airstack/node" ;
init ( "YOUR_AIRSTACK_API_KEY" );
const query = `YOUR_QUERY` ; // Replace with GraphQL Query
const { data , error } = await fetchQuery (query);
console .log ( "data:" , data);
console .log ( "error:" , error);
Copy import asyncio
from airstack . execute_query import AirstackClient
api_client = AirstackClient (api_key = "YOUR_AIRSTACK_API_KEY" )
query = """YOUR_QUERY""" # Replace with GraphQL Query
async def main ():
execute_query_client = api_client . create_execute_query_object (
query = query)
query_response = await execute_query_client . execute_query ()
print (query_response.data)
asyncio . run ( main ())
Other Programming Languages
To access the Airstack APIs in other languages, you can use https://api.airstack.xyz/gql as your GraphQL endpoint.
Get All ERC20s Owned By Solana Address
You can fetch all ERC20 tokens on Ethereum, Base, Degen Chain, and other Airstack-supported chains owned by any Solana address:
Try Demo
Code
Query Response
Copy query MyQuery {
TokenBalances(
input: {
filter : {
owner : { _eq : "HsXZnF7Te7dZ5ijvGcDj3NWtxRBBaAuYQgh1oZLwAba2" }
tokenType : { _eq : ERC20 }
}
blockchain : ethereum
limit : 50
}
) {
TokenBalance {
formattedAmount
tokenAddress
token {
name
symbol
}
}
}
}
Copy {
"data" : {
"TokenBalances" : {
"TokenBalance" : [
{
"formattedAmount" : 292.26813975 ,
"tokenAddress" : "0xa0b73e1ff0b80914ab6fe0444e65848c4c34450b" ,
"token" : {
"name" : "CRO" ,
"symbol" : "CRO"
}
}
// Other Ethereum ERC20 tokens
]
}
}
}
Get All NFTs Owned By Solana Address
You can fetch all NFT collections on Ethereum, Base, Degen Chain, and other Airstack-supported chains owned by any Solana address by using the TokenBalances
API:
Try Demo
Code
Query Response
Copy query MyQuery {
Ethereum : TokenBalances(
input: {
filter : {
owner : { _eq : "GJQUFnCu7ZJHxtxeaeskjnqyx8QFAN1PsiGuShDMPsqV" }
tokenType : { _in : [ERC721, ERC1155] }
}
blockchain : ethereum
limit : 50
}
) {
TokenBalance {
formattedAmount
tokenAddress
token {
name
symbol
}
tokenNfts {
contentValue {
image {
medium
}
}
}
}
}
Base : TokenBalances(
input: {
filter : {
owner : { _eq : "GJQUFnCu7ZJHxtxeaeskjnqyx8QFAN1PsiGuShDMPsqV" }
tokenType : { _in : [ERC721, ERC1155] }
}
blockchain : base
limit : 50
}
) {
TokenBalance {
formattedAmount
tokenAddress
token {
name
symbol
}
tokenNfts {
contentValue {
image {
medium
}
}
}
}
}
Zora : TokenBalances(
input: {
filter : {
owner : { _eq : "GJQUFnCu7ZJHxtxeaeskjnqyx8QFAN1PsiGuShDMPsqV" }
tokenType : { _in : [ERC721, ERC1155] }
}
blockchain : zora
limit : 50
}
) {
TokenBalance {
formattedAmount
tokenAddress
token {
name
symbol
}
tokenNfts {
contentValue {
image {
medium
}
}
}
}
}
}
Copy {
"data" : {
"Ethereum" : {
"TokenBalance" : [
{
"formattedAmount" : 1 ,
"tokenAddress" : "0xa723a8a69d9b8cf0bc93b92f9cb41532c1a27f8f" ,
"token" : {
"name" : "farcasting no. 1" ,
"symbol" : "FARCASTING"
} ,
"tokenNfts" : {
"contentValue" : {
"image" : {
"medium": "https://assets.airstack.xyz/image/nft/WAqW4V7VQ9ZvDl+JZt9C8PsLG21w5O9LGYQ2aWiLoXTV+fg5rhY0nW5nvymkVgGvjYYZevGHKzZVnizh6wkByg==/medium.png"
}
}
}
}
// Other Ethereum NFTs
]
} ,
"Base" : {
"TokenBalance" : [
{
"formattedAmount" : 1 ,
"tokenAddress" : "0x0e76013ff360eea66b19e5dce6e0c697036bc2c0" ,
"token" : {
"name" : "SocialGraphs" ,
"symbol" : "SG"
} ,
"tokenNfts" : {
"contentValue" : {
"image" : {
"medium": "https://assets.airstack.xyz/image/nft/8453/Bx023e1+9XnGFYLY5nEdSzmVHMVoGlt4mMbmM3F558B2aoRCT4cMX5Bmy6Y92lszy9MOpLE6QJJmsH6pXO3Fkg==/medium.aaf"
}
}
}
}
// Other Base NFTs
]
} ,
"Zora" : {
"TokenBalance" : [
{
"formattedAmount" : 1 ,
"tokenAddress" : "0xb9e43d3fc1c1d030d2fdab5e3b3326bb6b7526d5" ,
"token" : {
"name" : "in-motion images" ,
"symbol" : ""
} ,
"tokenNfts" : {
"contentValue" : {
"image" : {
"medium": "https://assets.airstack.xyz/image/nft/7777777/jhHqmdPsuhVIQnq/ea2L6VhKmtzJnwC2hEqIo3MIiYevip3jE36pj6LInDr3psjkBacwsGHPKauxhMxtI3svkw==/medium.png"
}
}
}
}
// Other Zora NFTs
]
}
}
}
Get All POAPs Attended By Solana Address
You can fetch all POAP events attended by any Solana address by using the Poaps
API:
Try Demo
Code
Query Response
Copy query MyQuery {
Poaps(
input: {
filter : { owner : { _eq : "GJQUFnCu7ZJHxtxeaeskjnqyx8QFAN1PsiGuShDMPsqV" } }
blockchain : ALL
}
) {
Poap {
eventId
tokenId
poapEvent {
eventName
description
}
}
}
}
Copy {
"data" : {
"Poaps" : {
"Poap" : [
{
"eventId" : "167485" ,
"tokenId" : "7002301" ,
"poapEvent" : {
"eventName" : "You've Met Jye - February 2024" ,
"description": "A digital collectible as proof of meeting with Jye in February 24'. Whether catch up's in London and Paris to NFT Paris and side-events around it to the classic virtual call, it was nice to meet and look forward to staying in touch.\n\nhttps://nf.td/sandiforward"
}
} ,
{
"eventId" : "150716" ,
"tokenId" : "6800204" ,
"poapEvent" : {
"eventName" : "You've met marpar.eth - September 2023" ,
"description": "You met Mariano (marpar.eth) IRL during September 2023.\r\n \r\n Website: https://chainjet.io \r\n Telegram: marian2js \r\n Twitter: marian2js \r\n POAP created using welook.io"
}
} ,
{
"eventId" : "150398" ,
"tokenId" : "6798634" ,
"poapEvent" : {
"eventName" : "Firefly at ETHGlobal New York 2023" ,
"description" : "This POAP commemorates meeting with Firefly at ETHGlobal New York 2023."
}
}
// Other POAPs
]
}
}
}
Developer Support
If you have any questions or need help regarding fetching token balances of a solana address, please join our Airstack's Telegram group.
More Resources