With nested queries, Airstack finds the intersection of common holders of various ERC20s, NFTs, and POAPs in the following order:
Filtering holders on the 1st outermost query
Comparing holders of 1st outermost query against the holders of 2nd outermost query
Comparing holders of the 1st and 2nd outermost query against the holders on the 3rd outermost query
Comparing holders of 1st, 2nd, ..., nth outermost query against the holders on (n + 1)-th outermost query
Since the number of objects returned in the responses will be dependent on the number of holders on the 1st outermost query, it's most efficient that you have the ERC20, NFT, or POAP with the least amount of holders on the 1st outermost query.
Suppose there is a token (ERC20 or NFT) and a POAP:
Token A: 100,000 holders
POAP B: 1,000 holders.
If Token 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 A Token (ERC20 or NFT) and A POAP
Fetching
You can fetch the common holder of a token and a POAP by providing the token contract address and the POAP event ID:
defformat_function(data): result = []if data isnotNoneand'TokenBalances'in data and'TokenBalance'in data['TokenBalances']:for item in data['TokenBalances']['TokenBalance']:if'owner'in item and'poaps'in item['owner']:for poap in item['owner']['poaps']:if'owner'in poap and'addresses'in poap['owner']: result.append(poap['owner']['addresses']) result = [item for sublist in result for item in sublist] result = [item for sublist in result for item in sublist] result =list(set(result))return result
The final result will the the list of all common holders in an array:
defformat_function(data): result = []if data isnotNoneand'TokenBalances'in data and'TokenBalance'in data['TokenBalances']:for item in data['TokenBalances']['TokenBalance']:if'owner'in item and'poaps'in item['owner']:for poap in item['owner']['poaps']:if'owner'in poap and'tokenBalances'in poap['owner']:for token_balance in poap['owner']['tokenBalances']:if'owner'in token_balance and'addresses'in token_balance['owner']: result.append(token_balance['owner']['addresses']) result = [item for sublist in result for item in sublist] result = [item for sublist in result for item in sublist] result = [item for sublist in result for item in sublist] result =list(set(result))return result
The final result will the the list of all common holders in an array: