Skip to main content

Claim Everyday Rewards

In this tutorial, you will learn how to claim the user's everyday rewards by calling the Moxie Everyday Rewards Claim API API.

Pre-requisites

  1. Install dependencies graphqlandgraphql-request to your project :
npm install graphql graphql-request
  1. Your Airstack API key will need to be allow listed to have access to the Moxie Everyday Rewards Claim API. To request access, please fill in this form here.

  2. Have checked that the user has available rewards to claim and the available rewards to claim are greater than the minimum claim amount, currently set at 1 Moxie. You can check the user's available rewards to claim from this tutorial here. If no claim is available, this API will throw an error.

Step 1: Add The API Mutation To Your Code

To claim the user's everyday rewards, you can use the following mutation:

mutation FarcasterUserClaimMoxie(
$fid: Int!
$preferredConnectedWallet: String!
) {
FarcasterUserClaimMoxie(
input: { fid: $fid, preferredConnectedWallet: $preferredConnectedWallet }
) {
fid
availableClaimAmount
minimumClaimableAmountInWei
availableClaimAmountInWei
claimedAmount
claimedAmountInWei
processingAmount
processingAmountInWei
tokenAddress
chainId
transactionId
transactionHash
transactionStatus
transactionAmount
transactionAmountInWei
rewardsLastEarnedTimestamp
}
}
With this GraphQL mutation, you can add it to your source code and call the API with the graphql-request library:
index.ts
import { gql, GraphQLClient } from "graphql-request";
import { config } from "dotenv";

config();

const graphQLClient = new GraphQLClient(
"https://claims.airstack.xyz/moxie"
);

const query = gql`
mutation FarcasterUserClaimMoxie(
$fid: Int!
$preferredConnectedWallet: String!
) {
FarcasterUserClaimMoxie(
input: { fid: $fid, preferredConnectedWallet: $preferredConnectedWallet }
) {
fid
availableClaimAmount
minimumClaimableAmountInWei
availableClaimAmountInWei
claimedAmount
claimedAmountInWei
processingAmount
processingAmountInWei
tokenAddress
chainId
transactionId
transactionHash
transactionStatus
transactionAmount
transactionAmountInWei
rewardsLastEarnedTimestamp
}
}
`;

const variable = {
fid: 3,
preferredConnectedWallet: "<FARCASTER_VERIFIED_WALLET>"
}

const headers = {
// Add Airstack API key here
"x-airstack-claims": process.env.AIRSTACK_API_KEY as string,
}

try {
const data = await graphQLClient.request(query, variable, headers);
console.log(data);
} catch (e) {
throw new Error(e);
}

Step 2: Execute Your Code

Once you have your code ready, you can execute it by running the following command:

ts-node index.ts

If it runs successfully, you should see the data returned in the terminal:

{
"FarcasterUserClaimMoxie": {
"fid": "15971",
"availableClaimAmount": 0,
"minimumClaimableAmountInWei": "1000000000000000000",
"availableClaimAmountInWei": "0",
"claimedAmount": 0,
"claimedAmountInWei": "0",
"processingAmount": 1206.299242863659,
"processingAmountInWei": "1206299242863658974356",
"tokenAddress": "0x8C9037D1Ef5c6D1f6816278C7AAF5491d24CD527",
"chainId": 8453,
"transactionId": "0d9b17b2-07e2-41cb-8cf6-f8351ec7f669",
"transactionHash": "0x30e12445cc1375f544f99486d36fd144038007488e36f83ed90a2b79950dd66e",
"transactionStatus": "REQUESTED",
"transactionAmount": 1206.299242863659,
"transactionAmountInWei": "1206299242863658974356",
"rewardsLastEarnedTimestamp": "2024-08-15T00:00:00.000Z"
}
}

Congrats! 🥳🎉 You've just successfully claimed the user's Moxie everyday rewards!

Next, you can take the transactionId field to check the claim transaction status in this tutorial here.

Developer Support

If you have any questions or need help with other use cases, feel free to join the /airstack Warpcast channel and ask your questions there.

Our team is always ready to help you with any questions you may have.