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
  • "I want to know the reaction rankings of the FIDs that have interacted with my most recent 100 casts. Who's been reacting to my posts the most?"
  • Step 1 : To determine the reaction rankings, we'll first need to identify the necessary data.
  • Step 2 : To use Lum0x, you need to get an API key.
  • Step 3 : Write business logic
  • Step 4 (Optional) : Frame generator on https://buildathon.lum0x.com/
  1. Lum0x-sdk
  2. Examples

Case 1 : Find my Fan

guide on how to create the desired frame using Lum0x.

"I want to know the reaction rankings of the FIDs that have interacted with my most recent 100 casts. Who's been reacting to my posts the most?"

Step 1 : To determine the reaction rankings, we'll first need to identify the necessary data.

  • Retrieves and processes Casts for a specific user, calculates scores, and returns a sorted list of users. Lum0x.farcasterCast.getCastsByFid

    async function searchMyFan(fid) {
        let res = await Lum0x.farcasterCast.getCastsByFid({
            fid: fid,
            limit: 100
        });
    
        let casts = res.result.casts;
        for (let cast of casts) {
            processReaction(cast);
        }
        const sortedFids = getSortedScores();
    
        sortedFids.splice(25);
    
        let fids = '';
        for (let info of sortedFids) {
            fids += info.fid + ',';
        }
        fids = fids.slice(0, -1);
        let displayNames = await getDisplayName(fids);
    
        for (let i = 0; i < sortedFids.length; i++) {
            sortedFids[i].display_name = displayNames[i];
        }
    
        return sortedFids;
    }

  • Retrieves the display names of users given their FIDs Lum0x.farcasterUser.getUserByFids

    async function getDisplayName(fids) {
        let res = await Lum0x.farcasterUser.getUserByFids({
            fids: fids
        });
        let users = res.users;
        let displayNames = [];
        for (let user of users) {
            displayNames.push(user.display_name);
        }
        return displayNames;
    }

Step 2 : To use Lum0x, you need to get an API key.

2) farcaster login

3) Get API key

Step 3 : Write business logic

1) Install Lum0x SDK

npm install lum0x-sdk

2) code

index.js
import { Lum0x } from "lum0x-sdk";

Lum0x.init('USE-YOUR-LUM0X-API-KEY'); 

let scoreBoard = {};

let reactionScore = 1;
let recastScore = 3;

// Sorts the scores of users in descending order.
function getSortedScores() {
    const scoresArray = Object.entries(scoreBoard).map(([fid, score]) => ({
        fid,
        score
    }));

    scoresArray.sort((a, b) => b.score - a.score);

    return scoresArray;
}

// Retrieves the display names of users given their FIDs.
async function getDisplayName(fids) {
    let res = await Lum0x.farcasterUser.getUserByFids({
        fids: fids
    });
    let users = res.users;
    let displayNames = [];
    for (let user of users) {
        displayNames.push(user.display_name);
    }
    return displayNames;
}

// Updates the scoreBoard based on reactions and recasts for a given Cast.
function processReaction(cast) {
    let reactions = cast.reactions.fids;
    let recasts = cast.recasts.fids;
    for (let reactionFid of reactions) {
        if (scoreBoard[reactionFid] === undefined) {
            scoreBoard[reactionFid] = 0;
        }
        scoreBoard[reactionFid] += reactionScore;
    }

    for (let recastFid of recasts) {
        if (scoreBoard[recastFid] === undefined) {
            scoreBoard[recastFid] = 0;
        }
        scoreBoard[recastFid] += recastScore;
    }
}

/* Retrieves and processes Casts for a specific user, 
calculates scores, and returns a sorted list of users.*/
async function searchMyFan(fid) {
    let res = await Lum0x.farcasterCast.getCastsByFid({
        fid: fid,
        limit: 100
    });

    let casts = res.result.casts;
    for (let cast of casts) {
        processReaction(cast);
    }
    const sortedFids = getSortedScores();

    sortedFids.splice(25);

    let fids = '';
    for (let info of sortedFids) {
        fids += info.fid + ',';
    }
    fids = fids.slice(0, -1);
    let displayNames = await getDisplayName(fids);

    for (let i = 0; i < sortedFids.length; i++) {
        sortedFids[i].display_name = displayNames[i];
    }

    return sortedFids;
}

// Entry point for executing the searchMyFan function.
export async function main(fid) {
    return await searchMyFan(fid);
}

package.json
{
  "name": "clitest8989",
  "version": "1.0.0",
  "main": "index.js", //!!!!! essential!!!!!
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "lum0x-sdk": "^1.0.32"
  },
  "type": "module". //!!!!! essential!!!!!
}

Step 4 (Optional) : Frame generator on https://buildathon.lum0x.com/

When data is entered, a table-like frame is automatically generated.

1) Adjust the data format as follows

The supported data formats are as follows.

  • CSV(Comma-Separated Values)

[
    [userId,gender,phone],
    [aglj34g34g ,male   ,01        ],
    [rnklbhn94  ,female ,02        ],
    [br9yn3     ,male   ,000034034 ]
]

The first row serves as a header, representing the name of each column (userId, gender, phone). Each subsequent row represents a record (or data entry), containing values corresponding to each column.

  • JSON (JavaScript Object Notation)

[
  {
    "fid": "610697",
    "score": 10,
    "display_name": "Mr.Bublegum"
  },
  {
    "fid": "648129",
    "score": 9,
    "display_name": "Tarun Chitra"
  },
  {
    "fid": "613104",
    "score": 7,
    "display_name": "Coly1986"
  },
  {
    "fid": "7074",
    "score": 6,
    "display_name": "0x_King"
  }
]

PreviousExamplesNextCase 2: Fetch user's Moxie earning

Last updated 9 months ago

1) Go to

buildathon.lum0x.com
Frame generator
Auto generated frame using Lum0x Frame generator