MOXIE đ Farcaster Moxie Rewards EarningsLearn how to fetch Farcaster Moxie Rewards earned by Farcaster users, channels, and the Farcaster network. In addition, learn how to sort by the earnings to get the top earners of Moxie.
Introduction
The Moxie Protocol enables Farcaster Members to earn Everyday Rewards based on who engages with their casts. Developers can also earn rewards for each unique FID who interacts with their frames.
Learn more about Moxie Everyday Rewards
Table Of Contents
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.
Get Moxie Earning For Certain User
You can fetch the Moxie earnings for a certain user by specifying entityType
as USER
and add the FID of the user in entityId
:
Try Demo
Code
Query Response
Copy query MyQuery {
FarcasterMoxieEarningStats(
input: {
timeframe : LIFETIME,
blockchain : ALL,
filter : {
# specify entity as USER
entityType : { _eq : USER},
# specify the FID of the user
entityId : { _eq : "3" }
}
}
) {
FarcasterMoxieEarningStat {
allEarningsAmount
allEarningsAmountInWei
castEarningsAmount
castEarningsAmountInWei
entityId
entityType
frameDevEarningsAmount
frameDevEarningsAmountInWei
otherEarningsAmount
otherEarningsAmountInWei
timeframe
}
}
}
Copy {
"data" : {
"FarcasterMoxieEarningStats" : {
"FarcasterMoxieEarningStat" : [
{
"allEarningsAmount" : 6434663.061487857 ,
"allEarningsAmountInWei" : "6434663061487857000000000" ,
"castEarningsAmount" : 6434663.061487857 ,
"castEarningsAmountInWei" : "6434663061487857000000000" ,
"entityId" : "3" ,
"entityType" : "USER" ,
"frameDevEarningsAmount" : 0 ,
"frameDevEarningsAmountInWei" : "0" ,
"otherEarningsAmount" : 0 ,
"otherEarningsAmountInWei" : "0" ,
"timeframe" : "LIFETIME"
}
]
}
}
}
Get Moxie Earning For Certain Channel
You can fetch the Moxie earnings for a certain channel by specifying entityType
as CHANNEL
and add the channel ID in entityId
:
Try Demo
Code
Query Response
Copy query MyQuery {
FarcasterMoxieEarningStats(
input: {
timeframe : LIFETIME,
blockchain : ALL,
filter : {
# Specify entity as CHANNEL
entityType : { _eq : CHANNEL},
# Specify the channel ID of the Farcaster channel
entityId : { _eq : "airstack" }
}
}
) {
FarcasterMoxieEarningStat {
allEarningsAmount
allEarningsAmountInWei
castEarningsAmount
castEarningsAmountInWei
entityId
entityType
frameDevEarningsAmount
frameDevEarningsAmountInWei
otherEarningsAmount
otherEarningsAmountInWei
timeframe
}
}
}
Copy {
"data" : {
"FarcasterMoxieEarningStats" : {
"FarcasterMoxieEarningStat" : [
{
"allEarningsAmount" : 102340.89672629537 ,
"allEarningsAmountInWei" : "102340896726295370000000" ,
"castEarningsAmount" : 84181.52016860196 ,
"castEarningsAmountInWei" : "84181520168601950000000" ,
"entityId" : "airstack" ,
"entityType" : "CHANNEL" ,
"frameDevEarningsAmount" : 16410 ,
"frameDevEarningsAmountInWei" : "16410000000000000000000" ,
"otherEarningsAmount" : 1749.3765576934104 ,
"otherEarningsAmountInWei" : "1749376557693410500000" ,
"timeframe" : "LIFETIME"
}
]
}
}
}
Get Moxie Earning For Farcaster Network
You can fetch the Moxie earnings for the Farcaster network by specifying entityType
as NETWORK
and add the channel ID in entityId
:
Try Demo
Code
Query Response
Copy query MyQuery {
FarcasterMoxieEarningStats(
input: {
timeframe : LIFETIME,
blockchain : ALL,
filter : {
# Specify entity as NETWORK
entityType : { _eq : NETWORK}
}
}
) {
FarcasterMoxieEarningStat {
allEarningsAmount
allEarningsAmountInWei
castEarningsAmount
castEarningsAmountInWei
entityId
entityType
frameDevEarningsAmount
frameDevEarningsAmountInWei
otherEarningsAmount
otherEarningsAmountInWei
timeframe
}
}
}
Copy {
"data" : {
"FarcasterMoxieEarningStats" : {
"FarcasterMoxieEarningStat" : [
{
"allEarningsAmount" : 872358.5098993169 ,
"allEarningsAmountInWei" : "872358509899317000000000" ,
"castEarningsAmount" : 860028.509899317 ,
"castEarningsAmountInWei" : "860028509899317000000000" ,
"entityId" : "FARCASTER" ,
"entityType" : "NETWORK" ,
"frameDevEarningsAmount" : 12330 ,
"frameDevEarningsAmountInWei" : "12330000000000000000000" ,
"otherEarningsAmount" : 0 ,
"otherEarningsAmountInWei" : "0" ,
"timeframe" : "LIFETIME"
}
]
}
}
}
Top Moxie Earning Entities Based On Highest Moxie Earnings
You can fetch the top entities w/ highest Moxie earnings by specifying order.allEarnings
to DESC
:
Try Demo
Code
Query Response
Copy query MyQuery {
FarcasterMoxieEarningStats(
input: {
timeframe : LIFETIME,
blockchain : ALL,
filter : {
entityType : { _eq : USER} # alternatively can be CHANNEL
},
# Order by All earning for sorting by total earnings in
# descending order
order : { allEarnings : DESC}
}
) {
FarcasterMoxieEarningStat {
allEarningsAmount
allEarningsAmountInWei
castEarningsAmount
castEarningsAmountInWei
entityId
entityType
frameDevEarningsAmount
frameDevEarningsAmountInWei
otherEarningsAmount
otherEarningsAmountInWei
timeframe
}
}
}
Copy {
"data" : {
"FarcasterMoxieEarningStats" : {
"FarcasterMoxieEarningStat" : [
{
"allEarningsAmount" : 10136643.391825985 ,
"allEarningsAmountInWei" : "10136643391825986000000000" ,
"castEarningsAmount" : 51821.7356651616 ,
"castEarningsAmountInWei" : "51821735665161600000000" ,
"entityId" : "336022" ,
"entityType" : "USER" ,
"frameDevEarningsAmount" : 0 ,
"frameDevEarningsAmountInWei" : "0" ,
"otherEarningsAmount" : 10084821.656160824 ,
"otherEarningsAmountInWei" : "10084821656160823000000000" ,
"timeframe" : "LIFETIME"
} ,
// Other top Farcaster user with most Moxie earned
]
}
}
}
Developer Support
If you have any questions or need help regarding fetching Moxie earnings data, please join our Airstack's Telegram group.
More Resources
Last updated 4 months ago