πŸ’°Get Token Balances

Learn how to get ERC20, 721, 1155, and POAPs of Farcaster User(s), including images and metadata, on Ethereum, Base, Degen L3, Gnosis (POAPs), and other Airstack-supported chains.

Airstack provides easy-to-use APIs for enriching Farcaster applications and for integrating onchain and offchain data with Farcaster.

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.

πŸ€– AI Natural Language​

Airstack provides an AI solution for you to build GraphQL queries to fulfill your use case easily. You can find the AI prompt of each query in the demo's caption or title for yourself to try.

Get Ethereum ERC20s Owned By Farcaster user(s)

You can fetch all ERC20 tokens on Ethereum owned by any Farcaster user(s) using either their Farcaster names or IDs:

Try Demo

Show ERC20 tokens on Ethereum owned by Farcaster user name dwr.eth and user id 1

Code

query ERC20sOwnedByFarcasterUser {
  TokenBalances(
    input: {
      filter: {
        owner: { _in: ["fc_fname:dwr.eth", "fc_fid:1"] }
        tokenType: { _eq: ERC20 }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: farcaster } } }) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      token {
        name
        symbol
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get Base ERC20s Owned By Farcaster user(s)

You can fetch all ERC20 tokens on Base owned by any Farcaster user(s) using either their Farcaster names or IDs:

Try Demo

Code

query ERC20sOwnedByFarcasterUser {
  TokenBalances(
    input: {
      filter: {
        owner: { _in: ["fc_fname:dwr.eth", "fc_fid:1"] }
        tokenType: { _eq: ERC20 }
      }
      blockchain: base
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: farcaster } } }) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      token {
        name
        symbol
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get All ERC20s Owned By Farcaster user(s)

You can fetch all ERC20 tokens on Ethereum, Base, and Zora owned by any Farcaster user(s) using either their Farcaster names or IDs:

Try Demo

Show ERC20 tokens on Ethereum and Base owned by Farcaster user name dwr.eth and user id 1

Code

query ERC20sOwnedByFarcasterUser {
  Ethereum: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["fc_fname:dwr.eth", "fc_fid:1"] }
        tokenType: { _eq: ERC20 }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: farcaster } } }) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      token {
        name
        symbol
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
  Base: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["fc_fname:dwr.eth", "fc_fid:1"] }
        tokenType: { _eq: ERC20 }
      }
      blockchain: base
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: farcaster } } }) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      token {
        name
        symbol
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get Ethereum NFTs Owned By Farcaster user(s)

You can fetch all NFTs on Ethereum owned by any Farcaster user(s) using either their Farcaster names or IDs:

Try Demo

Code

query NFTsOwnedByFarcasterUser {
  TokenBalances(
    input: {
      filter: {
        owner: { _in: ["fc_fname:dwr.eth", "fc_fid:1"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: farcaster } } }) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      tokenId
      tokenType
      tokenNfts {
        contentValue {
          image {
            extraSmall
            small
            medium
            large
          }
        }
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get Base NFTs Owned By Farcaster user(s)

You can fetch all NFTs on Base owned by any Farcaster user(s) using either their Farcaster names or IDs:

Try Demo

Code

query NFTsOwnedByFarcasterUser {
  TokenBalances(
    input: {
      filter: {
        owner: { _in: ["fc_fname:dwr.eth", "fc_fid:1"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: base
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: farcaster } } }) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      tokenId
      tokenType
      tokenNfts {
        contentValue {
          image {
            extraSmall
            small
            medium
            large
          }
        }
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get All NFTs Owned By Farcaster user(s)

You can fetch all NFTs on Ethereum, Base, and Zora owned by any Farcaster user(s) using either their Farcaster names or IDs:

Try Demo

Code

query NFTsOwnedByFarcasterUser {
  Ethereum: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["fc_fname:dwr.eth", "fc_fid:1"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: farcaster } } }) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      tokenId
      tokenType
      tokenNfts {
        contentValue {
          image {
            extraSmall
            small
            medium
            large
          }
        }
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
  Base: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["fc_fname:dwr.eth", "fc_fid:1"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: base
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: farcaster } } }) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      tokenId
      tokenType
      tokenNfts {
        contentValue {
          image {
            extraSmall
            small
            medium
            large
          }
        }
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get All POAPs Owned By Farcaster user(s)

You can fetch all POAPs tokens owned by any Farcaster user(s) using either their Farcaster names or IDs:

Try Demo

Code

query POAPsOwnedByFarcasterUser {
  Poaps(
    input: {
      filter: { owner: { _in: ["fc_fname:dwr.eth", "fc_fid:1"] } }
      blockchain: ALL
    }
  ) {
    Poap {
      eventId
      poapEvent {
        eventName
        eventURL
        startDate
        endDate
        country
        city
        contentValue {
          image {
            extraSmall
            large
            medium
            original
            small
          }
        }
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}