đ° WalletLearn how to use Airstack to fetch onchain and offchain data of a wallet, which includes, ENS, Lens, Farcaster, XMTP, token balances, etc.
Airstack provides easy-to-use Wallet API for enriching Web3 applications with onchain and offchain data of a wallet, which includes, ENS, Lens, Farcaster, XMTP, token balances, etc.
Table Of Contents
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
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 (data) {
return < p >Data: { JSON .stringify (data)}</ p >;
}
if (loading) {
return < p >Loading...</ p >;
}
if (error) {
return < p >Error: { error .message}</ p >;
}
};
Copy import { init , fetchQuery } from "@airstack/node" ;
init ( "YOUR_AIRSTACK_API_KEY" );
const query = `YOUR_QUERY` ; // Replace with GraphQL Query
const { data , error } = await 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 All User's ENS Domain
You can use Wallet
API to fetch all user's ENS domains (including primary and non-primary):
If a user have more than 200 ENS domains resolved to the address, then it is recommended that you use the Domains API directly instead.
Try Demo
Code
Query Response
Copy query MyQuery {
Wallet(
input: {
identity : "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
blockchain : ethereum
}
) {
domains(input: { limit : 200 }) {
name
isPrimary
}
}
}
Copy {
"data" : {
"Wallet" : {
"domains" : [
{
"name" : "quantumexchange.eth" ,
"isPrimary" : false
} ,
{
"name" : "7860000.eth" ,
"isPrimary" : false
} ,
{
"name" : "vitalik.eth" ,
"isPrimary" : true
}
// More ENS domain
]
}
}
}
Get All User's Lens Profiles
You can use Wallet
API to fetch all user's Lens profiles:
If a user have more than 200 Lens profiles owned by the address, then it is recommended that you use the Socials API directly instead.
For more details, follow this guide here .
Try Demo
Code
Query Response
Copy query MyQuery {
Wallet(
input: {
identity : "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
blockchain : ethereum
}
) {
socials(input: { limit : 200 , filter : { dappName : { _eq : lens } } }) {
profileName
}
}
}
Copy {
"data" : {
"Wallet" : {
"socials" : [
{
"profileName" : "lens/@vitalik"
}
]
}
}
}
Get All User's Farcaster Account
You can use Wallet
API to fetch all user's Farcaster accounts:
If a user have more than 200 Farcaster accounts owned by the address, then it is recommended that you use the Socials API directly instead.
Try Demo
Code
Query Response
Copy query MyQuery {
Wallet(
input: {
identity : "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
blockchain : ethereum
}
) {
socials(input: { limit : 200 , filter : { dappName : { _eq : farcaster } } }) {
profileName
}
}
}
Copy {
"data" : {
"Wallet" : {
"socials" : [
{
"profileName" : "vitalik.eth"
}
]
}
}
}
Check If A User Have XMTP Enabled
You can use Wallet
API to check if a user has XMTP enabled:
Try Demo
Code
Query Response
Copy query MyQuery {
Wallet(
input: {
identity : "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
blockchain : ethereum
}
) {
xmtp {
isXMTPEnabled
}
}
}
Copy {
"data" : {
"Wallet" : {
"xmtp" : [
{
"isXMTPEnabled" : true
}
]
}
}
}
Get User's Token Balances
You can use Wallet
API to fetch all user's token (ERC20/721/1155) balances across Ethereum, Base, Degen Chain, and other Airstack-supported chains :
For fetching token balances data from multiple chains, check out Cross-Chain Queries .
If a user have more than 200 tokens on a chain , then it is recommended that you use the TokenBalances API directly instead.
For more details, follow this guide here .
Try Demo
Code
Query Response
Copy query MyQuery {
Wallet(
input: {
identity : "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
blockchain : ethereum
}
) {
tokenBalances {
tokenAddress
tokenId
tokenType
token {
name
symbol
}
}
}
}
Copy {
"data" : {
"Wallet" : {
"tokenBalances" : [
{
"tokenAddress" : "0x00000000366b8a1ec86d6c8e00c861bf2245d946" ,
"tokenId" : "" ,
"tokenType" : "ERC20" ,
"token" : {
"name" : "iPhone 15" ,
"symbol" : "iPhone15" ,
"logo" : {
"external" : null ,
"small" : null ,
"medium" : null ,
"large" : null ,
"original" : null
}
} ,
"tokenNfts" : null
}
// Other Ethereum tokens
]
}
}
}
Get User's Token Transfers
You can use Wallet
API to fetch all user's token (ERC20/721/1155) transfers across Ethereum, Base, Degen Chain, and other Airstack-supported chains :
For fetching token transfers data from multiple chains, check out Cross-Chain Queries .
If a user have more than 200 token transfers on a chain , then it is recommended that you use the TokenTransfers API directly instead.
For more details, follow this guide here .
Try Demo
Code
Query Response
Copy query MyQuery {
Wallet(
input: {
identity : "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
blockchain : ethereum
}
) {
tokenTransfers {
from {
addresses
}
to {
addresses
}
tokenAddress
tokenId
tokenType
token {
name
symbol
}
}
}
}
Copy {
"data" : {
"Wallet" : {
"tokenTransfers" : [
{
"from" : {
"addresses" : [ "0xd8da6bf26964af9d7eed9e03e53415d37aa96045" ] ,
]
} ,
"to" : {
"addresses" : [ "0xd8b75eb7bd778ac0b3f5ffad69bcc2e25bccac95" ] ,
]
} ,
"tokenAddress" : "0xc791c23da1161f8259c9094b65cf13f9d891a892" ,
"tokenId" : "606" ,
"tokenType" : "ERC721" ,
"token" : {
"name" : "Mars Mining Company" ,
"symbol" : "MARS" ,
} ,
}
// Other Ethereum token transfers
] ,
}
}
}
Developer Support
If you have any questions or need help regarding fetching balance snapshots data, please join our Airstack's Telegram group.
More Resources