⚡Multiple POAPs

Learn how to fetch the list of common POAP holders or event attendees of multiple POAPs.

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 (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.

Best Practices

With nested queries, Airstack finds the intersection of common holders of multiple POAPs in the following order:

  1. Filtering POAP holders on the 1st outermost query

  2. Comparing POAP holders of 1st outermost query against the POAP holders on 2nd outermost query

  3. Comparing POAP holders of the 1st and 2nd outermost query against the POAP holders on the 3rd outermost query

  4. Comparing POAP holders of 1st, 2nd, ..., nth outermost query against the POAP holders on (n + 1)-th outermost query

Since the number of objects returned in the responses will be dependent on the number of POAP holders on the 1st outermost query, it's most efficient that you have the POAP with the least amount of holders on the 1st outermost query.

Suppose there are two POAPs:

  • POAP A: 100,000 holders

  • POAP B: 1,000 holders.

If POAP A is the input on the 1st outermost query, then the end result will be 100,000 objects in the response array.

On the other hand, if POAP B is the input on the 1st outermost query, then the end result will be instead ONLY 1,000 objects in the response array.

The latter approach will be more efficient and easier for further formatting.

Common Holders of 2 POAPs

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

All the common holders' addresses will be returned inside the innermost owner.addresses field.

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?.addresses)
  )
    .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:

[
  "0xc77d249809ae5a118eef66227d1a01a3d62c82d4",
  "0x3291e96b3bff7ed56e3ca8364273c5b4654b2b37",
  "0xe348c7959e47646031cea7ed30266a6702d011cc",
  // ...other token holders
  "0xa69babef1ca67a37ffaf7a485dfff3382056e78c",
  "0x46340b20830761efd32832a74d7169b29feb9758",
  "0x2008b6c3d07b061a84f790c035c2f6dc11a0be70"
]

Common Holders of More Than 2 POAPs

Fetching

Fetching common holders for more than 2 POAPs works the same way as fetching only 2 POAPs with the addition of more POAP event ID parameters and additional nesting as shown below:

Try Demo

Code

query GetCommonHoldersOfMoreThanTwoPOAPs {
  Poaps(input: {filter: {eventId: {_eq: "80393"}}, blockchain: ALL, limit: 200}) {
    Poap {
      owner {
        poaps(input: {blockchain: ALL, filter: {eventId: {_eq: "79011"}}}) {
          owner {
            poaps(input: {blockchain: ALL, filter: {eventId: {_eq: "15678"}}}) {
              owner {
                addresses
              }
            }
          }
        }
      }
    }
  }
}

All the common holders' addresses will be returned inside the innermost owner.addresses field.

Formatting

const formatFunction = (data) =>
  data?.Poaps?.Poap?.map(({ owner }) =>
    owner?.poaps?.map(({ owner }) =>
      owner?.poaps?.map(({ owner }) => owner?.addresses)
    )
  )
    .filter(Boolean)
    .flat(3)
    .filter((address, index, array) => array.indexOf(address) === index) ?? [];

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

Was this helpful?