Guides đŋ LensđĒ Tokenbound ERC6551 AccountsLearn how to get ERC6551 Accounts owned By Lens profile(s). Get Lens profile who own NFTs owned by ERC6551 accounts.
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 ERC6551 accounts and all assets held inside the account that is owned by a Lens profile(s).
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
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 ERC6551 Account Addresses of Lens Profile(s)
Try Demo
Show all ERC6551 accounts owned by jayden.lens Code
Query Response
Copy query MyQuery {
TokenBalances(
input: { filter : { owner : { _in : [ "jayden.lens" ]}}, blockchain : ethereum, limit : 200 }
) {
TokenBalance {
tokenNfts {
erc6551Accounts {
address {
addresses
}
}
}
}
}
}
Copy {
"data" : {
"TokenBalances" : {
"TokenBalance" : [
{
"tokenNfts" : {
"erc6551Accounts" : [
{
"address" : {
"addresses" : [
"0x5416e5dc14caa0950b2a24ede1eb0e97c360bcf5"
]
}
}
]
}
} ,
{
"tokenNfts" : {
"erc6551Accounts" : null
}
}
]
}
}
}
Get Assets Owned by ERC6551 Accounts of Lens Profile(s)
Try Demo
Show all assets owned by ERC6551 accounts owned by jayden.lens Code
Query Response
Copy query MyQuery {
TokenBalances(
input: { filter : { owner : { _in : [ "jayden.lens" ]}}, blockchain : ethereum, limit : 200 }
) {
TokenBalance {
tokenNfts {
erc6551Accounts {
address {
addresses
tokenBalances {
tokenAddress
tokenId
amount
token {
name
symbol
tokenNfts {
contentValue {
image {
extraSmall
large
medium
original
small
}
}
}
}
}
}
}
}
}
}
}
Copy {
"data" : {
"TokenBalances" : {
"TokenBalance" : [
{
"tokenNfts" : {
"erc6551Accounts" : [
{
"address" : {
"addresses" : [
"0x5416e5dc14caa0950b2a24ede1eb0e97c360bcf5"
] ,
"tokenBalances" : [
{
"tokenAddress" : "0x8ee9a60cb5c0e7db414031856cb9e0f1f05988d1" ,
"tokenId" : "9707" ,
"amount" : "1" ,
"token" : {
"name" : "STAPLEVERSE - FEED CLAN" ,
"symbol" : "FEED" ,
"tokenNfts" : [
{
"contentValue" : {
"image" : {
"extraSmall" : "https://assets.airstack.xyz/image/nft/1/0x8ee9a60cb5c0e7db414031856cb9e0f1f05988d1/1/extra_small" ,
"large" : "https://assets.airstack.xyz/image/nft/1/0x8ee9a60cb5c0e7db414031856cb9e0f1f05988d1/1/large" ,
"medium" : "https://assets.airstack.xyz/image/nft/1/0x8ee9a60cb5c0e7db414031856cb9e0f1f05988d1/1/medium" ,
"original" : "https://assets.airstack.xyz/image/nft/1/0x8ee9a60cb5c0e7db414031856cb9e0f1f05988d1/1/original_image" ,
"small" : "https://assets.airstack.xyz/image/nft/1/0x8ee9a60cb5c0e7db414031856cb9e0f1f05988d1/1/small"
}
}
}
]
}
}
]
}
}
]
}
} ,
{
"tokenNfts" : {
"erc6551Accounts" : null
}
}
]
}
}
}
Get Lens Profile of Owner that Owns NFT that Owns ERC6551 Accounts
You can know whether an NFT is owned by an ERC6551 accounts and the NFT that own the account:
Try Demo
Show owner of NFT that owns ERC6551 account with address 0x5416e5dc14caa0950b2a24ede1eb0e97c360bcf5 Code
Query Response
Copy query MyQuery {
Accounts(
input: { filter : { address : { _in : "0x5416e5dc14caa0950b2a24ede1eb0e97c360bcf5" }}, blockchain : ethereum}
) {
Account {
nft {
tokenBalances {
owner {
addresses
socials(input: { filter : { dappName : { _eq : lens}}}) {
profileName
userId
}
}
}
}
}
}
}
Copy {
"data" : {
"Accounts" : {
"Account" : [
{
"nft" : {
"tokenBalances" : [
{
"owner" : {
"addresses" : [
"0xa75b7833c78eba62f1c5389f811ef3a7364d44de"
] ,
"socials" : [
{
"profileName" : "jayden.lens" ,
"userId" : "0xa75b7833c78eba62f1c5389f811ef3a7364d44de"
}
]
}
}
]
}
}
]
}
}
}
Developer Support
If you have any questions or need help regarding fetching token bound ERC6551 accounts, please join our Airstack's Telegram group.
More Resources