Guides đ Farcasterđ¤ Tokens In CommonLearn how to fetch ERC20, NFTs, or POAPs in common from multiple Farcaster users.
Airstack provides easy-to-use APIs for enriching Farcaster applications and for integrating onchain and offchain data with Farcaster.
In this tutorial, you will learn how to fetch ERC20, NFTs, or POAPs in common from multiple Farcaster users.
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.
ERC20 Tokens In Common Owned By Farcaster User(s)
You can fetch common ERC20 tokens of multiple Farcaster user(s):
Try Demo
Code
Query Response
Copy query MyQuery {
TokenBalances(
input: { filter : { owner : { _eq : "fc_fname:betashop.eth" }, tokenType : { _eq : ERC20}}, blockchain : polygon}
) {
TokenBalance {
token {
tokenBalances(
input: { filter : { owner : { _eq : "fc_fname:sarvesh" }, tokenType : { _eq : ERC20}}}
) {
id
token {
address
symbol
name
}
}
}
}
}
}
Copy {
"data" : {
"TokenBalances" : {
"TokenBalance" : [
{
"token" : {
"tokenBalances" : [
{
"id" : "51012959a2b4c04f8dba7ef03eff0ded99c7892e8367d023680d66825287fbba" ,
"token" : {
"address" : "0xef556c61263135ad91a27c8c891e61e521560240" ,
"symbol" : "usd-rewards.xyz" ,
"name" : "USD"
}
}
]
}
} ,
{
"token" : {
"tokenBalances" : [] // Owned by betashop.eth, but not owned by sarvesh
}
}
]
}
}
}
NFTs In Common Owned By Farcaster User(s)
You can fetch common NFTs of multiple Farcaster user(s):
Try Demo
Code
Query Response
Copy query MyQuery {
TokenBalances(
input: { filter : { owner : { _eq : "fc_fname:betashop.eth" }, tokenType : { _in : [ERC721, ERC1155]}}, blockchain : polygon}
) {
TokenBalance {
token {
tokenBalances(
input: { filter : { owner : { _eq : "fc_fname:sarvesh" }, tokenType : { _in : [ERC721, ERC1155]}}}
) {
id
token {
address
symbol
name
}
}
}
}
}
}
Copy {
"data" : {
"TokenBalances" : {
"TokenBalance" : [
{
"token" : {
"tokenBalances" : [
{
"id" : "05c4cece4238243f6f8fd6c22e0df78fa07450283322c476dc4af2e2a744c6d3" ,
"token" : {
"address" : "0x4c23d718416164b2f52f88dde4cf0b1172b741b6" ,
"symbol" : "swap-rewards.xyz" ,
"name" : "swap-rewards.xyz"
}
}
]
}
} ,
{
"token" : {
"tokenBalances" : [] // Owned by betashop.eth, but not owned by sarvesh
}
}
]
}
}
}
POAPs In Common Owned By Farcaster User(s)
You can fetch common POAPs of multiple Farcaster user(s):
Try Demo
Code
Query Response
Copy query MyQuery {
Poaps(
input: { filter : { owner : { _eq : "fc_fname:betashop.eth" }}, blockchain : ALL, order : { createdAtBlockNumber : DESC}}
) {
Poap {
poapEvent {
poaps(input: { filter : { owner : { _eq : "fc_fname:ipeciura" }}}) {
poapEvent {
eventName
eventId
endDate
country
city
}
}
}
}
}
}
Copy {
"data" : {
"Poaps" : {
"Poap" : [
{
"poapEvent" : {
"poaps" : [
{
"poapEvent" : {
"eventName" : "Airstack Amazing Race Dubai" ,
"eventId" : "145995" ,
"endDate" : "2023-07-30T00:00:00Z" ,
"country" : "UAE" ,
"city" : "Dubai"
}
}
]
}
} ,
{
"poapEvent" : {
"poaps" : [] // owned by betsahop.eth, but not ipeciura
}
}
]
}
}
}
Developer Support
If you have any questions or need help regarding fetching common ERC20 tokens, NFTs, or POAPs of multiple Farcaster users, please join our Airstack's Telegram group.
More Resources