đŸĨ‡Token Holders

Learn how to get all Farcaster users who own a specific token, NFT, or POAP, or a min amount of that token. Get combinations of NFTs or POAPs + Farcaster, e.g. Has POAP1 and POAP2 and has Farcaster

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

In this tutorial, you will learn how to fetch all Farcaster users who own a specific ERC20 token, NFT (ERC721 and ERC1155), or POAPs.

In addition, you will also learn how to fetch common Farcaster users that hold two different assets at the same time, e.g. Farcaster users that hold both EthLisbon and EthCC[6] POAP.

In this guide you will learn how to use Airstack to:

Pre-requisites

  • An Airstack account (free)

  • 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 (loading) {
    return <p>Loading...</p>;
  }

  if (error) {
    return <p>Error: {error.message}</p>;
  }

  // Render your component using the data returned by the query
};

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 Holders of an ERC20 Token That Has Farcaster

Fetching

You can get all holders of an ERC20 token that has Farcaster:

Try Demo

Code

query MyQuery {
  TokenBalances(
    input: {filter: {tokenAddress: {_eq: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174"}}, blockchain: polygon, limit: 200}
  ) {
    TokenBalance {
      owner {
        socials(input: {filter: {dappName: {_eq: farcaster}}}) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
    }
  }
}

Formatting

To get the list of all holders in a flat array, use the following format function:

const formatFunction = (data) =>
  data?.TokenBalances?.TokenBalance?.map(({ owner }) =>
    owner?.socials?.length > 0 ? owner?.socials : null
  )
    .filter(Boolean)
    .flat(2)
    .filter((address, index, array) => array.indexOf(address) === index) ?? [];

The final result will the the list of all common holders in an array:

[
  {
    "profileName": "vbuterin",
    "userId": "5650",
    "userAssociatedAddresses": [
      "0xadd746be46ff36f10c81d6e3ba282537f4c68077",
      "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
    ]
  },
  // ... other token holders
]

Get Holders of NFT That Has Farcaster

Fetching

You can get all holders of NFT that has Farcaster:

Try Demo

Code

query MyQuery {
  TokenBalances(
    input: {filter: {tokenAddress: {_eq: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"}}, blockchain: ethereum, limit: 200}
  ) {
    TokenBalance {
      owner {
        socials(
          input: {filter: {dappName: {_eq: farcaster}}}
        ) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
    }
  }
}

Formatting

To get the list of all holders in a flat array, use the following format function:

const formatFunction = (data) =>
  data?.TokenBalances?.TokenBalance?.map(({ owner }) =>
    owner?.socials?.length > 0 ? owner?.socials : null
  )
    .filter(Boolean)
    .flat(2)
    .filter((address, index, array) => array.indexOf(address) === index) ?? [];

The final result will the the list of all common holders in an array:

[
  {
    "profileName": "durtis",
    "userId": "11926",
    "userAssociatedAddresses": [
      "0xcb0b3404b7d5db8622511427c09a1bba450d3c0f",
      "0xe5ca890a0ef2f128eb3267e4711c6bf3306ec024"
    ]
  }
  // ... other token holders
]

Get Holders of POAP That Has Farcaster

Fetching

You can get all holders of POAP that has Farcaster:

Try Demo

Code

query MyQuery {
  Poaps(input: {filter: {eventId: {_eq: "141910"}}, blockchain: ALL, limit: 50}) {
    Poap {
      owner {
        socials(input: {filter: {dappName: {_eq: farcaster}}}) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
    }
  }
}

Formatting

To get the list of all holders in a flat array, use the following format function:

const formatFunction = (data) =>
  data?.Poaps?.Poap?.map(({ owner }) =>
    owner?.socials?.length > 0 ? owner?.socials : null
  )
    .filter(Boolean)
    .flat(2)
    .filter((address, index, array) => array.indexOf(address) === index) ?? [];

The final result will the the list of all common holders in an array:

[
  {
    "profileName": "megankaspar",
    "userId": "7361",
    "userAssociatedAddresses": [
      "0xadf37a0d500c748edb1c689a1be26472e583dcb5",
      "0x4455951fa43b17bd211e0e8ae64d22fb47946ade",
      "0xfaedb341b0faced023099d7b0ccd23c2ec5ed7a5"
    ]
  },
  // ... other token holders
]

Get Holders That Held Specific Amount of ERC20 Token

Fetching

You can get all holders of an ERC20 token that have a minimum amount held in their balances which also have Farcaster:

Try Demo

Code

query MyQuery {
  TokenBalances(
    input: {
      filter: {
        tokenAddress: {_eq: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"}, 
        formattedAmount: {_gte: 10}
      }, 
      blockchain: ethereum, 
      limit: 200
    }
  ) {
    TokenBalance {
      owner {
        identity
        socials(input: {filter: {dappName: {_eq: farcaster}}}) {
          profileName
          userId
          userAssociatedAddresses
        }
      }
    }
  }
}

Formatting

To get the list of all holders in a flat array, use the following format function:

const formatFunction = (data) =>
  data?.TokenBalances?.TokenBalance?.map(({ owner }) =>
    owner?.socials?.length > 0 ? owner?.socials : null
  )
    .filter(Boolean)
    .flat(2)
    .filter((address, index, array) => array.indexOf(address) === index) ?? [];

The final result will the the list of all common holders in an array:

[
  {
    "profileName": "durtis",
    "userId": "11926",
    "userAssociatedAddresses": [
      "0xcb0b3404b7d5db8622511427c09a1bba450d3c0f",
      "0xe5ca890a0ef2f128eb3267e4711c6bf3306ec024"
    ]
  }
  // ... other token holders
]

Get Common Holders of 2 ERC20 Tokens That Has Farcaster

Fetching

You can fetch the common holders of two given ERC20, e.g. USDT and USDC:

query GetCommonHoldersOfUSDTAndUSDC {
  TokenBalances(input: {filter: {tokenAddress: {_eq: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}}, blockchain: ethereum, limit: 200}) {
    TokenBalance {
      owner {
        tokenBalances(input: {filter: {tokenAddress: {_eq: "0xdAC17F958D2ee523a2206206994597C13D831ec7"}}, limit: 200}) {
          owner {
            socials(input: {filter: {dappName: {_eq: farcaster}}}) {
              profileName
              userId
              userAssociatedAddresses
            }
          }
        }
      }
    }
  }
}

All the common holders' Farcaster details will be returned inside the innermost owner.socials field.

Formatting

To get the list of all holders in a flat array, use the following format function:

const formatFunction = (data) =>
  data?.TokenBalances?.TokenBalance?.map(({ owner }) =>
    owner?.tokenBalances?.map(({ owner }) =>
      owner?.socials?.length > 0 ? owner?.socials : null
    )
  )
    .filter(Boolean)
    .flat(2)
    .filter((address, index, array) => array.indexOf(address) === index) ?? [];

The final result will the the list of all common holders in an array:

[
  {
    "profileName": "vbuterin",
    "userId": "5606",
    "userAssociatedAddresses": [
      "0xadd746be46ff36f10c81d6e3ba282537f4c68077",
      "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
    ]
  }
  // ... other token holders
]

Get Common Holders of Two POAPs and That Has Farcaster

Fetching

You can fetch the common holders of two given POAP event IDs, e.g. EthGlobal Lisbon 2023 Partner Attendee POAP & EthCC[6] Attendee POAP:

Try Demo

Code

query GetCommonHoldersOfEthGlobalLisbonAndEthCC {
  Poaps(input: {filter: {eventId: {_eq: "127462"}}, blockchain: ALL, limit: 200}) {
    Poap {
      owner {
        poaps(input: {blockchain: ALL, filter: {eventId: {_eq: "141910"}}}) {
          owner {
            socials(input: {filter: {dappName: {_eq: farcaster}}}) {
              profileName
              userId
              userAssociatedAddresses
            }
          }
        }
      }
    }
  }
}

All the common holders' Farcaster details will be returned inside the innermost owner.socials field.

If user has any Farcaster, then socials will have non-null value and profileName and userId will show both the Farcaster name and ID, respectively.

Formatting

To get the list of all holders in a flat array, use the following format function:

const formatFunction = (data) =>
  data?.Poaps?.Poap?.map(({ owner }) =>
    owner?.poaps?.map(({ owner }) =>
      owner?.socials?.length > 0 ? owner?.socials : null
    )
  )
    .filter(Boolean)
    .flat(2)
    .filter((address, index, array) => array.indexOf(address) === index) ?? [];

The final result will the the list of all common holders in an array:

[
  {
    "profileName": "schmidsi",
    "userId": "14088",
    "userAssociatedAddresses": [
      "0xcc8fd0d88abf88d006fea4487e59e2b39f281095",
      "0x546457bbddf5e09929399768ab5a9d588cb0334d"
    ]
  },
  // ...other token holders
]

Get Common Holders of A Token (ERC20 or NFT) and A POAP That Has Farcaster

Fetching

You can fetch the common holder of a token and a POAP by providing the token contract address and the POAP event ID:

Try Demo

Show common holders of Nouns NFT and EthCC POAP that also have Farcaster

Code

query GetCommonHoldersOfNounsAndEthCC {
  TokenBalances(
    input: {filter: {tokenAddress: {_eq: "0x9c8ff314c9bc7f6e59a9d9225fb22946427edc03"}}, blockchain: ethereum, limit: 200}
  ) {
    TokenBalance {
      owner {
        poaps(input: {filter: {eventId: {_eq: "141910"}}}) {
          owner {
            socials(input: {filter: {dappName: {_eq: farcaster}}}) {
              profileName
              userId
              userAssociatedAddresses
            }
          }
        }
      }
    }
  }
}

All the common holders' Farcaster details will be returned inside the innermost owner.socials field.

Formatting

To get the list of all holders in a flat array, use the following format function:

const formatFunction = (data) =>
  data?.TokenBalances?.TokenBalance?.map(({ owner }) =>
    owner?.poaps?.map(({ owner }) => owner?.socials)
  )
    .filter(Boolean)
    .flat(2)
    .filter((social, index, array) => array.indexOf(social) === index) ?? [];

The final result will the the list of all common holders in an array:

[
  {
    "profileName": "worthalter",
    "userId": "9456",
    "userAssociatedAddresses": [
      "0xc19628f57a46389b0ac0fc113de273f91b07faca",
      "0xf6b6f07862a02c85628b3a9688beae07fea9c863"
    ]
  },
  // ...other token holders
]

Developer Support

If you have any questions or need help regarding fetching holders or attendees of multiple POAPs, please join our Airstack's Telegram group.

More Resources

Last updated

#300: add-user-details

Change request updated