provides easy-to-use APIs for enriching applications and integrating on-chain and off-chain data with .
In this tutorial, you will learn how to fetch Lens user(s) asset holdings which comprise ERC20s, ERC721s, ERC115s, and POAPs on Ethereum, Polygon, and Gnosis.
In this guide you will learn how to use Airstack to:
Pre-requisites
Basic knowledge of GraphQL
Get Started
JavaScript/TypeScript/Python
If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:
npm yarn pnpm pip
React
Copy npm install @airstack/airstack-react
Node
Copy npm install @airstack/node
React
Copy yarn add @airstack/airstack-react
Node
Copy yarn add @airstack/node
React
Copy pnpm install @airstack/airstack-react
Node
Copy pnpm install @airstack/node
Copy pip install airstack asyncio
Then, add the following snippets to your code:
React Node Python
Copy 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
};
Copy import { init, fetchQuery } from "@airstack/airstack-react";
init("YOUR_AIRSTACK_API_KEY");
const query = "YOUR_QUERY"; // Replace with GraphQL Query
const { data, error } = fetchQuery(query);
console.log("data:", data);
console.log("error:", error);
Copy import asyncio
from airstack.execute_query import AirstackClient
api_client = AirstackClient(api_key="YOUR_AIRSTACK_API_KEY")
query = "YOUR_QUERY" # Replace with GraphQL Query
async def main():
execute_query_client = api_client.create_execute_query_object(
query=query)
query_response = await execute_query_client.execute_query()
print(query_response.data)
asyncio.run(main())
Other Programming Languages
Get All ERC20s Owned By Lens Profile(s)
You can fetch all ERC20 tokens on Ethereum and Polygon owned by any Lens Profile(s):
Try Demo
Code
Query Response
Copy query ERC20OwnedByLensProfiles {
Ethereum: TokenBalances(
input: {filter: {owner: {_in: ["bradorbradley.lens", "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
}
}
Polygon: TokenBalances(
input: {filter: {owner: {_in: ["bradorbradley.lens", "lens_id:100275"]}, tokenType: {_eq: ERC20}}, blockchain: polygon, limit: 50}
) {
TokenBalance {
owner {
socials(input: {filter: {dappName: {_eq: lens}}}) {
profileName
profileTokenId
profileTokenIdHex
userAssociatedAddresses
}
}
amount
tokenAddress
token {
name
symbol
}
}
pageInfo {
nextCursor
prevCursor
}
}
}
Copy {
"data": {
"Ethereum": {
"TokenBalance": [
{
"owner": {
"socials": [
{
"profileName": "vitalik.lens",
"profileTokenId": "100275",
"profileTokenIdHex": "0x0187b3",
"userAssociatedAddresses": [
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
]
}
]
},
"amount": "45934484403886362668",
"tokenAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"token": {
"name": "Wrapped Ether",
"symbol": "WETH"
}
}
]
},
"Polygon": {
"TokenBalance": [
{
"owner": {
"socials": [
{
"profileName": "bradorbradley.lens",
"profileTokenId": "36",
"profileTokenIdHex": "0x024",
"userAssociatedAddresses": [
"0x8ec94086a724cbec4d37097b8792ce99cadcd520"
]
}
]
},
"amount": "457218374987121000000",
"tokenAddress": "0x086373fad3447f7f86252fb59d56107e9e0faafa",
"token": {
"name": "Yup",
"symbol": "YUP"
}
}
]
}
}
}
Get All NFTs Owned By Lens Profile(s)
You can fetch all NFTs on Ethereum and Polygon owned by any Lens Profile(s):
Try Demo
Code
Query Response
Copy query NFTsOwnedByLensProfiles {
Ethereum: TokenBalances(
input: {filter: {owner: {_in: ["bradorbradley.lens", "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
}
}
Polygon: TokenBalances(
input: {filter: {owner: {_in: ["bradorbradley.lens", "lens_id:100275"]}, tokenType: {_in: [ERC1155, ERC721]}}, blockchain: polygon, 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
}
}
}
Copy {
"data": {
"Ethereum": {
"TokenBalance": [
{
"owner": {
"socials": [
{
"profileName": "vitalik.lens",
"profileTokenId": "100275",
"profileTokenIdHex": "0x0187b3",
"userAssociatedAddresses": [
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
]
}
]
},
"amount": "1",
"tokenAddress": "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85",
"tokenId": "93631715144692179688067815556165775057916676179424585455268666624027958254283",
"tokenType": "ERC721",
"tokenNfts": {
"contentValue": {
"image": {
"extraSmall": "https://assets.airstack.xyz/image/nft/nNBFvZ6wvuIHqDzTFi5pM/pM0Q1IAUgJRNTJrw7f4s3ANGkOaqLt5uB0akSKQqzzwkFP2k3F+pM22yvq3atTA66A1hk52OxQkPc5GWp5cl6hkqffkEcsvP3JAWyEPPyYsKMKIbbP1VsMuvSSOA7NTW+/a2HkQPhYY/PVrG6O9Is=/extra_small.svg",
"small": "https://assets.airstack.xyz/image/nft/nNBFvZ6wvuIHqDzTFi5pM/pM0Q1IAUgJRNTJrw7f4s3ANGkOaqLt5uB0akSKQqzzwkFP2k3F+pM22yvq3atTA66A1hk52OxQkPc5GWp5cl6hkqffkEcsvP3JAWyEPPyYsKMKIbbP1VsMuvSSOA7NTW+/a2HkQPhYY/PVrG6O9Is=/small.svg",
"medium": "https://assets.airstack.xyz/image/nft/nNBFvZ6wvuIHqDzTFi5pM/pM0Q1IAUgJRNTJrw7f4s3ANGkOaqLt5uB0akSKQqzzwkFP2k3F+pM22yvq3atTA66A1hk52OxQkPc5GWp5cl6hkqffkEcsvP3JAWyEPPyYsKMKIbbP1VsMuvSSOA7NTW+/a2HkQPhYY/PVrG6O9Is=/medium.svg",
"large": "https://assets.airstack.xyz/image/nft/nNBFvZ6wvuIHqDzTFi5pM/pM0Q1IAUgJRNTJrw7f4s3ANGkOaqLt5uB0akSKQqzzwkFP2k3F+pM22yvq3atTA66A1hk52OxQkPc5GWp5cl6hkqffkEcsvP3JAWyEPPyYsKMKIbbP1VsMuvSSOA7NTW+/a2HkQPhYY/PVrG6O9Is=/large.svg"
}
}
}
}
]
},
"Polygon": {
"TokenBalance": [
{
"owner": {
"socials": [
{
"profileName": "bradorbradley.lens",
"userId": "0x8ec94086a724cbec4d37097b8792ce99cadcd520",
"profileTokenId": "36",
"profileTokenIdHex": "0x024",
"userAssociatedAddresses": [
"0x8ec94086a724cbec4d37097b8792ce99cadcd520"
]
}
]
},
"amount": "1",
"tokenAddress": "0x5ef718b8360ef2b82fb971b50350913e2bad4783",
"tokenId": "2525",
"tokenType": "ERC1155",
"tokenNfts": {
"contentValue": {
"image": {
"extraSmall": "https://assets.airstack.xyz/image/nft/137/0x5ef718b8360ef2b82fb971b50350913e2bad4783/2525/extra_small.png",
"small": "https://assets.airstack.xyz/image/nft/137/0x5ef718b8360ef2b82fb971b50350913e2bad4783/2525/small.png",
"medium": "https://assets.airstack.xyz/image/nft/137/0x5ef718b8360ef2b82fb971b50350913e2bad4783/2525/medium.png",
"large": "https://assets.airstack.xyz/image/nft/137/0x5ef718b8360ef2b82fb971b50350913e2bad4783/2525/large.png"
}
}
}
}
]
}
}
}
Get All POAPs Owned By Lens Profile(s)
You can fetch all POAPs tokens owned by any Lens Profile(s):
Try Demo
Code
Query Response
Copy query POAPsOwnedByLensProfiles {
Poaps(
input: {filter: {owner: {_in: ["bradorbradley.lens", "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
}
}
}
}
}
}
Copy {
"data": {
"Poaps": {
"Poap": [
{
"eventId": "80393",
"owner": {
"socials": [
{
"profileName": "vitalik.lens",
"profileTokenId": "100275",
"profileTokenIdHex": "0x0187b3",
"userAssociatedAddresses": [
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
]
}
]
},
"poapEvent": {
"eventName": "You met Cryptocomical at Lisbon 2022",
"eventURL": "https://cards.io",
"startDate": "2022-10-30T00:00:00Z",
"endDate": "2022-11-15T00:00:00Z",
"country": "Portugal",
"city": "Lisbon",
"contentValue": {
"image": {
"extraSmall": "https://assets.airstack.xyz/image/poap/SAZVBaiZmZwlX6c7OxyUGw==/extra_small.png",
"large": "https://assets.airstack.xyz/image/poap/SAZVBaiZmZwlX6c7OxyUGw==/large.png",
"medium": "https://assets.airstack.xyz/image/poap/SAZVBaiZmZwlX6c7OxyUGw==/medium.png",
"original": "https://assets.airstack.xyz/image/poap/SAZVBaiZmZwlX6c7OxyUGw==/original_image.png",
"small": "https://assets.airstack.xyz/image/poap/SAZVBaiZmZwlX6c7OxyUGw==/small.png"
}
}
}
},
{
"eventId": "47553",
"owner": {
"socials": [
{
"profileName": "bradorbradley.lens",
"profileTokenId": "36",
"profileTokenIdHex": "0x024",
"userAssociatedAddresses": [
"0x8ec94086a724cbec4d37097b8792ce99cadcd520"
]
}
]
},
"poapEvent": {
"eventName": "Proof of rAAVE - ETHCC Paris 2022",
"eventURL": "https://aave.com",
"startDate": "2022-07-01T00:00:00Z",
"endDate": "2022-07-01T00:00:00Z",
"country": "",
"city": "",
"contentValue": {
"image": {
"extraSmall": "https://assets.airstack.xyz/image/poap/FpLVsf5or7YFwItupydyOg==/extra_small.png",
"large": "https://assets.airstack.xyz/image/poap/FpLVsf5or7YFwItupydyOg==/large.png",
"medium": "https://assets.airstack.xyz/image/poap/FpLVsf5or7YFwItupydyOg==/medium.png",
"original": "https://assets.airstack.xyz/image/poap/FpLVsf5or7YFwItupydyOg==/original_image.png",
"small": "https://assets.airstack.xyz/image/poap/FpLVsf5or7YFwItupydyOg==/small.png"
}
}
}
}
]
}
}
}
Developer Support
More Resources