๐Ÿ’ฐGet Token Balances

Learn how to get ERC20, 721, 1155, and POAPs Of Lens Profile(s), including images and metadata, on Ethereum, Base, Zora, Gnosis (POAPs), and other Airstack-supported chains.

Airstack provides easy-to-use APIs for enriching Lens applications and integrating on-chain and off-chain data with Lens.

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 Ethereum ERC20s Owned By Lens Profile(s)

You can fetch all ERC20 tokens on Ethereum owned by any Lens Profile(s):

Try Demo

Show ERC20 tokens on Ethereum owned by lens/@bradorbradley and Lens profile id 100275

Code

query MyQuery {
  TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley", "lens_id:100275"] }
        tokenType: { _eq: ERC20 }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      token {
        name
        symbol
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get Base ERC20s Owned By Lens Profile(s)

You can fetch all ERC20 tokens on Base owned by any Lens Profile(s):

Try Demo

Code

query MyQuery {
  TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley", "lens_id:100275"] }
        tokenType: { _eq: ERC20 }
      }
      blockchain: base
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      token {
        name
        symbol
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get All ERC20s Owned By Lens Profile(s)

You can fetch all ERC20 tokens on Ethereum, Base, Degen Chain, and other Airstack-supported chains owned by any Lens Profile(s):

Try Demo

Show ERC20 tokens on Ethereum and Base owned by lens/@bradorbradley and Lens profile id 100275

Code

query ERC20OwnedByLensProfiles {
  Ethereum: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley", "lens_id:100275"] }
        tokenType: { _eq: ERC20 }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      token {
        name
        symbol
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
  Base: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley", "lens_id:100275"] }
        tokenType: { _eq: ERC20 }
      }
      blockchain: base
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      token {
        name
        symbol
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get Ethereum NFTs Owned By Lens Profile(s)

You can fetch all NFTs on Ethereum owned by any Lens Profile(s):

Try Demo

Code

query MyQuery {
  TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley", "lens_id:100275"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      tokenId
      tokenType
      tokenNfts {
        contentValue {
          image {
            extraSmall
            small
            medium
            large
          }
        }
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get Base NFTs Owned By Lens Profile(s)

You can fetch all NFTs on Base owned by any Lens Profile(s):

Try Demo

Code

query MyQuery {
  TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley", "lens_id:100275"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: base
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      tokenId
      tokenType
      tokenNfts {
        contentValue {
          image {
            extraSmall
            small
            medium
            large
          }
        }
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get All NFTs Owned By Lens Profile(s)

You can fetch all NFTs on Ethereum, Base, Degen Chain, and other Airstack-supported chains owned by any Lens Profile(s):

Try Demo

Code

query NFTsOwnedByLensProfiles {
  Ethereum: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley", "lens_id:100275"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      tokenId
      tokenType
      tokenNfts {
        contentValue {
          image {
            extraSmall
            small
            medium
            large
          }
        }
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
  Base: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley", "lens_id:100275"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: base
      limit: 50
    }
  ) {
    TokenBalance {
      owner {
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
      }
      amount
      tokenAddress
      tokenId
      tokenType
      tokenNfts {
        contentValue {
          image {
            extraSmall
            small
            medium
            large
          }
        }
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

Get All POAPs Owned By Lens Profile(s)

You can fetch all POAPs tokens owned by any Lens Profile(s):

Try Demo

Code

query POAPsOwnedByLensProfiles {
  Poaps(
    input: {
      filter: { owner: { _in: ["lens/@bradorbradley", "lens_id:100275"] } }
      blockchain: ALL
    }
  ) {
    Poap {
      eventId
      owner {
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
          userAssociatedAddresses
        }
      }
      poapEvent {
        eventName
        eventURL
        startDate
        endDate
        country
        city
        contentValue {
          image {
            extraSmall
            large
            medium
            original
            small
          }
        }
      }
    }
  }
}

Developer Support

If you have any questions or need help regarding fetching token balances of Lens profile(s), please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?