✂ī¸Farcaster Cast Moxie Earning Details

Learn how to fetch the Moxie earning details of casts and replies and how it is split among the casters and fan token holders.

Introduction

The Moxie Protocol enables Farcaster Members to earn Everyday Rewards based on who engages with their casts. These rewards are automatically split as follows:

  • 50% to the member who casted

  • 20% to their Fans (holders of their Fan Tokens)

  • 20% to the Fans of the Channel casted into (holders of their Fan Tokens)

  • 10% to Fans of Farcaster overall (holders of the Fan Tokens)

Learn more about Moxie Everyday Rewards

Table Of Contents

In this tutorial, you will learn various use cases to get Moxie earning details of a cast and how they are split among members and Fan Token holders:

Pre-requisites

  • An Airstack account

  • Basic knowledge of GraphQL

Get Started

JavaScript/TypeScript/Python

If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:

React

npm install @airstack/airstack-react

Node

npm install @airstack/node

Then, add the following snippets to your code:

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>;
  }
};

Other Programming Languages

To access the Airstack APIs in other languages, you can use https://api.airstack.xyz/gql as your GraphQL endpoint.

Get User's Casts With Their Moxie Earning Details

You can use the FarcasterCasts API to fetch all user's casts and get their Moxie earning details by providing the FID of the user to the castedBy filter input:

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        castedBy: {
          _eq: "fc_fid:602" # Specify user's FID here
        }
      },
      blockchain: ALL
    }
  ) {
    Cast {
      hash
      # Get the moxie earning details here
      moxieEarningsSplit {
        earnerType
        earningsAmount
        earningsAmountInWei
      }
    }
  }
}

If moxieEarningSplit is returned as null, then it implies that the cast has not earned any Moxie.

Get User's Replies With Their Moxie Earning Details

You can use the FarcasterReplies API to fetch all user's replies and get their Moxie earning details by providing the FID of the user to the repliedBy filter input:

Try Demo

Code

query MyQuery {
  FarcasterReplies(
    input: {
      filter: {
        repliedBy: {_eq: "fc_fid:602"} # Specify user's FID here
      },
      blockchain: ALL
    }
  ) {
    Reply {
      hash
      # Get the moxie earning details here
      moxieEarningsSplit {
        earnerType
        earningsAmount
        earningsAmountInWei
      }
    }
  }
}

If moxieEarningSplit is returned as null, then it implies that the cast has not earned any Moxie.

Get All Cast In A Channel And Their Moxie Earning Details

You can use the FarcasterCasts API to fetch all the casts casted in a certain channel and get their Moxie earning details by providing the channel URL to the rootParentUrl filter input:

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        rootParentUrl: {
          # Specify channel URL here
          _eq: "https://warpcast.com/~/channel/airstack"
        }
      },
      blockchain: ALL
    }
  ) {
    Cast {
      hash
      # Get the moxie earning details here
      moxieEarningsSplit {
        earnerType
        earningsAmount
        earningsAmountInWei
      }
      rootParentUrl
    }
  }
}

If moxieEarningSplit is returned as null, then it implies that the cast has not earned any Moxie.

Get Certain Cast Moxie Earning Details

You can use the FarcasterCasts API to fetch a certain cast and get its Moxie earning details by providing the cast hash to the hash filter input:

Try Demo

Code

query MyQuery {
  FarcasterCasts(
    input: {
      filter: {
        hash: {
          # specify the cast hash here
          _eq: "0x34e6bbb99b9166bc2098e109a328bdfd1dfaa207"
        }
      },
      blockchain: ALL
    }
  ) {
    Cast {
      hash
      # Get the moxie earning details here
      moxieEarningsSplit {
        earnerType
        earningsAmount
        earningsAmountInWei
      }
    }
  }
}

If moxieEarningSplit is returned as null, then it implies that the cast has not earned any Moxie.

Get Certain Reply Moxie Earning Details

You can use the FarcasterReplies API to fetch a certain reply and get its Moxie earning details by providing the cast hash to the hash filter input:

Try Demo

Code

query MyQuery {
  FarcasterReplies(
    input: {
      filter: {
        hash: {
          # specify the reply cast hash here
          _eq: "0x8db996f6515509d32fc1524740b8010839ca754b"
        }
      },
      blockchain: ALL
    }
  ) {
    Reply {
      hash
      # Get the moxie earning details here
      moxieEarningsSplit {
        earnerType
        earningsAmount
        earningsAmountInWei
      }
    }
  }
}

If moxieEarningSplit is returned as null, then it implies that the cast has not earned any Moxie.

Developer Support

If you have any questions or need help regarding fetching Moxie earnings details data on Farcaster casts and replies, please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?