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.functiongetSortedScores() {constscoresArray=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.asyncfunctiongetDisplayName(fids) {let res =awaitLum0x.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.functionprocessReaction(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.*/asyncfunctionsearchMyFan(fid) {let res =awaitLum0x.farcasterCast.getCastsByFid({ fid: fid, limit:100 });let casts =res.result.casts;for (let cast of casts) {processReaction(cast); }constsortedFids=getSortedScores();sortedFids.splice(25);let fids ='';for (let info of sortedFids) { fids +=info.fid +','; } fids =fids.slice(0,-1);let displayNames =awaitgetDisplayName(fids);for (let i =0; i <sortedFids.length; i++) { sortedFids[i].display_name = displayNames[i]; }return sortedFids;}// Entry point for executing the searchMyFan function.exportasyncfunctionmain(fid) {returnawaitsearchMyFan(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.
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.