βš–οΈToken Balances

Learn 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

  • An Airstack account

  • Basic knowledge of GraphQL

Get Started

JavaScript/TypeScript/Python

If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:

React

npm install @airstack/airstack-react

Node

npm install @airstack/node

Then, add the following snippets to your code:

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>;
  }
};

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:

For fetching ERC20 tokens owned across multiple chains, check out Cross-Chain Queries.

Try Demo

Code

query MyQuery {
  TokenBalances(
    input: {
      filter: {
        owner: { _eq: "HsXZnF7Te7dZ5ijvGcDj3NWtxRBBaAuYQgh1oZLwAba2" }
        tokenType: { _eq: ERC20 }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenBalance {
      formattedAmount
      tokenAddress
      token {
        name
        symbol
      }
    }
  }
}

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:

For fetching NFTs owned across multiple chains, e.g. Ethereum, Base, Degen Chain, and other Airstack-supported chains, check out Cross-Chain Queries.

Try Demo

Code

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
          }
        }
      }
    }
  }
}

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 MyQuery {
  Poaps(
    input: {
      filter: { owner: { _eq: "GJQUFnCu7ZJHxtxeaeskjnqyx8QFAN1PsiGuShDMPsqV" } }
      blockchain: ALL
    }
  ) {
    Poap {
      eventId
      tokenId
      poapEvent {
        eventName
        description
      }
    }
  }
}

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

Last updated

Was this helpful?