âĻī¸ NFTsLearn how to fetch NFTs in common from multiple users.
Airstack provides easy-to-use APIs for enriching dapps and integrating on-chain and off-chain data from Ethereum, Base, Degen Chain, and other Airstack-supported chains .
In this tutorial, you will learn how to fetch NFTs in common from multiple users.
In this guide, you will learn how to use Airstack to fetch NFTs In Common .
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
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 >;
}
};
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.
NFTs In Common
You can fetch common NFTs of multiple user(s) provided the user's 0x address, Farcaster name or ID, ENS domains, or Lens profile:
Try Demo
Code
Query Response
Copy query MyQuery {
TokenBalances(
input: {
filter : {
owner : { _eq : "betashop.eth" }
tokenType : { _in : [ERC721, ERC1155] }
}
blockchain : base
}
) {
TokenBalance {
token {
tokenBalances(
input: {
filter : {
owner : { _eq : "tokenstaker.eth" }
tokenType : { _in : [ERC721, ERC1155] }
}
}
) {
id
token {
address
symbol
name
}
}
}
}
}
}
Copy {
"data" : {
"TokenBalances" : {
"TokenBalance" : [
{
"token" : {
"tokenBalances" : [
{
"id" : "09adff7901e6b3ed411a037abf0be67365cb2dabe24e48921768d32abf64203a" ,
"token" : {
"address" : "0x4c17ff12d9a925a0dec822a8cbf06f46c626855c" ,
"symbol" : "FC-HZN" ,
"name" : "Farcaster Horizon"
}
}
]
}
} ,
{
"token" : {
"tokenBalances" : [] // Owned by betashop.eth, but not owned by tokenstaker.eth
}
}
]
}
}
}
Developer Support
If you have any questions or need help regarding fetching common NFTs of multiple users, please join our Airstack's Telegram group.
More Resources