Learn how to get all Lens profiles who own a specific token, NFT, or POAP, or a min amount of that token. Get combinations of NFTs or POAPs + Lens, e.g. Has POAP1 and POAP2 and has Lens profile
Airstack provides easy-to-use APIs for enriching Lens applications and integrating on-chain and off-chain data with Lens.
In this tutorial, you will learn how to fetch all Lens profiles that own a specific ERC20 token, NFT (ERC721 and ERC1155), or POAPs.
In addition, you will also learn how to fetch common Lens profiles that hold two different assets at the same time, e.g. Lens profiles that hold both EthLisbon and EthCC[6] POAP.
In this guide you will learn how to use Airstack to:
If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:
React
npminstall@airstack/airstack-react
Node
npminstall@airstack/node
React
yarnadd@airstack/airstack-react
Node
yarnadd@airstack/node
React
pnpminstall@airstack/airstack-react
Node
pnpminstall@airstack/node
pipinstallairstackasyncio
Then, add the following snippets to your code:
import { init, useQuery } from"@airstack/airstack-react";init("YOUR_AIRSTACK_API_KEY");constquery="YOUR_QUERY"; // Replace with GraphQL QueryconstComponent= () => {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};
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 Lens Profile
Fetching
You can get all holders of an ERC20 token that has a Lens Profile:
defformat_function(data): result = []if data and'TokenBalances'in data and'TokenBalance'in data['TokenBalances']:for item in data['TokenBalances']['TokenBalance']:if'owner'in item and'socials'in item['owner']andlen(item['owner']['socials'])>0: result.append(item['owner']['socials']) 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:
[ {"profileName":"lyska.lens","userId":"0x79eb30ff39ad0d2879ee1c0358170972e808cf7a","userAssociatedAddresses": ["0x79eb30ff39ad0d2879ee1c0358170972e808cf7a" ] },// ... other token holders]
Get Holders of NFT That Has Lens Profile
Fetching
You can get all holders of NFT that has Lens Profile:
defformat_function(data): result = []if data and'TokenBalances'in data and'TokenBalance'in data['TokenBalances']:for item in data['TokenBalances']['TokenBalance']:if'owner'in item and'socials'in item['owner']andlen(item['owner']['socials'])>0: result.append(item['owner']['socials']) 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:
[ {"profileName":"choccy.lens","userId":"0x9a41abee1477745ab8004ce129ad60f1231ef85b","userAssociatedAddresses": ["0x9a41abee1477745ab8004ce129ad60f1231ef85b" ] }// ... other token holders]
Get Holders of POAP That Has Lens Profile
Fetching
You can get all holders of POAP that has Lens Profile:
defformat_function(data): result = []if data and'Poaps'in data and'Poap'in data['Poaps']:for item in data['Poaps']['Poap']:if'owner'in item and'socials'in item['owner']andlen(item['owner']['socials'])>0: result.append(item['owner']['socials']) 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:
[ {"profileName":"0x131.lens","userId":"0x4455951fa43b17bd211e0e8ae64d22fb47946ade","userAssociatedAddresses": ["0x4455951fa43b17bd211e0e8ae64d22fb47946ade" ] },// ... 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 Lens Profile:
defformat_function(data): result = []if data and'TokenBalances'in data and'TokenBalance'in data['TokenBalances']:for item in data['TokenBalances']['TokenBalance']:if'owner'in item and'socials'in item['owner']andlen(item['owner']['socials'])>0: result.append(item['owner']['socials']) 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:
[ {"profileName":"monkeyflower.lens","userId":"0xd034fd34eaee5ec2c413c51936109e12873f4da5","userAssociatedAddresses": ["0xd034fd34eaee5ec2c413c51936109e12873f4da5" ] }// ... other token holders]
Get Common Holders of 2 ERC20 Tokens That Have Lens Profile
Fetching
You can fetch the common holders of two given ERC20, e.g. ApeCoin and USDC:
defformat_function(data): result = []if data and'TokenBalances'in data and'TokenBalance'in data['TokenBalances']:for item in data['TokenBalances']['TokenBalance']:if'owner'in item and'tokenBalances'in item['owner']:for token_balance in item['owner']['tokenBalances']:if'owner'in token_balance and'socials'in token_balance['owner']andlen(token_balance['owner']['socials'])>0: result.append(token_balance['owner']['socials']) 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:
[ {"profileName":"cryptoetc.lens","userId":"0x188c30e9a6527f5f0c3f7fe59b72ac7253c62f28","userAssociatedAddresses": ["0x188c30e9a6527f5f0c3f7fe59b72ac7253c62f28" ] }// ... other token holders]
Get Common Holders of Two POAPs and That Has Lens Profile
defformat_function(data): result = []if data and'Poaps'in data and'Poap'in data['Poaps']:for poap in data['Poaps']['Poap']:if'owner'in poap and'poaps'in poap['owner']:for owner_poap in poap['owner']['poaps']:if'owner'in owner_poap and'socials'in owner_poap['owner']andlen(owner_poap['owner']['socials'])>0: result.append(owner_poap['owner']['socials']) 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'socials'in poap['owner']: result.append(poap['owner']['socials']) 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: