Lum0x SDK
  • Lum0x-sdk
    • Getting started
    • Examples
      • Case 1 : Find my Fan
      • Case 2: Fetch user's Moxie earning
      • Case 3: Raffle events among the filtered casts
      • How to Deploy a Project with Vercel
    • FarcasterUser
      • Search for Usernames
      • Fetch users based on FIDs
      • Fetch power user objects
      • Fetches users based on Eth or Sol addresses
      • Lookup a user by custody-address
      • Retrieve all channels that a given fid follows
      • Get User Information by username
      • Get Recent Users
    • FarcasterCast
      • Retrieve cast for a given hash or Warpcast URL
      • Retrieve casts for a given user
      • Gets information about an array of casts
      • Retrieve the conversation for a given cast
      • Get Recent Casts
    • FarcasterFeed
      • Retrieve casts based on filters
      • Retrieve trending casts
    • FarcasterReaction
      • Fetches reactions for a given user
      • Fetches reactions for a given cast
    • FarcasterFollowers
      • Retrieve followers for a given user
      • Retrieve relevant followers for a given user
      • Retrieve a list of users followed by a user
    • FarcasterStorage
      • Fetches storage allocations for a given user
      • Fetches storage usage for a given user
    • FarcasterFname
      • Check if a given fname is available
    • FarcasterMute
      • Get fids that a user has muted
    • FarcasterChannel
      • Retrieve all channels with their details
      • Search for channels based on id or name
      • (Bulk) Retrieve channels by id or parent_url
      • Retrieve channel details by id or parent_url
      • Retrieve followers for a given channel
      • Get channels that a user is active in
      • Check If User Follows Channel
      • Retrieve trending channels based on activity
    • FarcasterNotification
      • Retrieve notifications for a given user
    • FarcasterMoxie
      • Retrieve Moxie earning status
      • Retrieve FarScore and FarRank
      • Retrieve Moxie airdrop claim status
      • Retrieve Moxie earning details for cast.
      • Retrieve Moxie earning details for reply.
      • Retrieve Moxie earning details for cast by fid.
      • Retrieve Moxie earning details for reply by fid.
      • Retrieve Moxie earning details from channel cast.
Powered by GitBook
On this page
  1. Lum0x-sdk
  2. Examples

Case 2: Fetch user's Moxie earning

guide on how to create the desired frame using frog.fm

PreviousCase 1 : Find my FanNextCase 3: Raffle events among the filtered casts

Last updated 9 months ago

** The full code for this example can be found .

** You can check the operation of the completed sample . ** This example demonstrates creating a frame via frog.fm. For more details about frog, please refer to the official documentation below.

This example creates a frame to view a specific user's moxie earning stat.

  1. How to get data with Lum0x SDK 1) The farcasterMoxie.getEarningStat function gets the moxie earning stat for a specific fid.

      let res = await Lum0x.farcasterMoxie.getEarningStat({
          entity_type: "USER",
          entity_id: fid.toString(),
          timeframe: "LIFETIME"
      });
      let LIFETIME_STAT = res.data.FarcasterMoxieEarningStats.FarcasterMoxieEarningStat;

    2) Lookup for each timeframe.

      let res = await Lum0x.farcasterMoxie.getEarningStat({
          entity_type: "USER",
          entity_id: fid.toString(),
          timeframe: "LIFETIME"
      });
      let LIFETIME_STAT = res.data.FarcasterMoxieEarningStats.FarcasterMoxieEarningStat;
    
      res = await Lum0x.farcasterMoxie.getEarningStat({
          entity_type: "USER",
          entity_id: fid.toString(),
          timeframe: "WEEKLY"
      });
      let WEEKLY_STAT = res.data.FarcasterMoxieEarningStats.FarcasterMoxieEarningStat;
    
      res = await Lum0x.farcasterMoxie.getEarningStat({
          entity_type: "USER",
          entity_id: fid.toString(),
          timeframe: "TODAY"
      });
    
      let TODAY_STAT = res.data.FarcasterMoxieEarningStats.FarcasterMoxieEarningStat;

  1. State Management 1) Setting initialState. (Set the initial targetFid to -1)

    const app = new Frog({
      assetsPath: "/",
      basePath: "/api",
      hub: neynar({ apiKey: process.env.NEYNAR_API_KEY ?? "" }),
      title: "Moxie Stat",
      imageAspectRatio: "1:1",
      imageOptions: {
        height: 800,
        width: 800,
      },
      initialState: {
        targetFid: -1
      },
    });

2) Update the state value with the value received as textInput (deriveState,previousState)

  const state = c.deriveState((previousState: any) => {
    previousState.targetFid = Number(c.inputText);
  });
  1. How to bind data with image 1) call getMoxieImage and pass return value to image field.

app.frame("/moxie-stat", async (c) => {
  const fid = c.frameData?.fid;
  await postLum0xTestFrameValidation(Number(fid), "moxie-stat");

  const state = c.deriveState((previousState: any) => {
    previousState.targetFid = Number(c.inputText);
  });

  return c.res({
    image: await getMoxieImage(c.inputText == "" ? fid : state.targetFid),
    intents: [
      <TextInput placeholder="Enter Fid" />,
      <Button action="/moxie-stat">Search</Button>
    ],
  });
});

2) getMoxieImage is return <Box>

export async function getMoxieImage(fid?: number) {

  let result = await moxieStat(Number(fid));

  return (
    <Box
      grow
      alignVertical="center"
      padding="10"
      paddingBottom="26"
      marginTop="2"
      marginBottom="2"
      fontWeight="700"
      position="relative"
    >
      <div
        style={{
          position: "absolute",
          display: "flex",
          top: 0,
          left: 0,
          width: "100%",
        }}
      >
        <img src="/Result.png" />
      </div>

      <div
        style={{
          position: "absolute",
          display: "flex",
          top: 365,
          left: 90,
          width: 500,
          height: 45,
          color: "white",
          fontSize: 44,
          fontFamily: "coinbase",
        }}
      >
        {`${result.LIFETIME} MOXIE`}
      </div>


      <div
        style={{
          position: "absolute",
          display: "flex",
          top: 500,
          left: 90,
          width: 500,
          height: 45,
          color: "white",
          fontSize: 44,
          fontFamily: "coinbase",
        }}
      >
        {`${result.WEEKLY} MOXIE`}
      </div>

      <div
        style={{
          position: "absolute",
          display: "flex",
          top: 635,
          left: 90,
          width: 500,
          height: 45,
          color: "white",
          fontSize: 44,
          fontFamily: "coinbase",
        }}
      >
        {`${result.TODAY} MOXIE`}
      </div>


    </Box>
  );
}

4. Add postLum0xTestFrameValidation

call postLum0xTestFrameValidation when every frame page loads.

This makes track frame usage and generate dashboard page.

app.frame("/moxie-stat", async (c) => {
  const fid = c.frameData?.fid;
  await postLum0xTestFrameValidation(Number(fid), "moxie-stat");

  const state = c.deriveState((previousState: any) => {
    previousState.targetFid = Number(c.inputText);
  });

  return c.res({
    image: await getMoxieImage(c.inputText == "" ? fid : state.targetFid),
    intents: [
      <TextInput placeholder="Enter Fid" />,
      <Button action="/moxie-stat">Search</Button>
    ],
  });
});

Please deploy the completed project code on Vercel. For instructions on how to deploy via Vercel, refer to this guide .

here
here
here
https://frog.fm/getting-started