Skip to content

Latest commit

 

History

History
263 lines (203 loc) · 7.18 KB

certain-farcaster-user.md

File metadata and controls

263 lines (203 loc) · 7.18 KB
description
Learn how to use Airstack to show Trending Casts of a specific user FID on Farcaster based on various engagement criteria.

🟪 Certain Farcaster User

{% embed url="https://www.youtube.com/watch?v=x1yLbP4ZbFY&t=212s" %} Get Trending User's Cast Tutorial {% endembed %}

Criteria

Airstack provides multiple ways to fetch Trending Casts of a specific user FID:

NameValueDescription
criteria

social_capital_value |

likes |
recasts |
replies | likes_recasts_replies |

This will calculate and sort the Farcaster casts based on the chosen criteria:
- social_capital_value(Recommended): the social capital value associated with the cast
- likes: number of likes on the cast
- recasts: number of recasts on the cast
- replies: number of replies on the cast
- likes_recasts_replies: number of total likes, recasts, and replies on the cast combined
fidIntSpecify the FID of the Farcaster user for whom you wish to retrieve the trending cast from.
timeFrameone_hour |
two_hours |
four_hours |
eight_hours | twelve_hours |
one_day |
two_days |
seven_days
Only fetch trending casts that have the most engagement within the chosen time frame, e.g. one_hour will fetch trending Farcaster casts with the most engagement for the last 1 hour.

Social Capital Value & Social Capital Scores

A new metric, Social Capital Value (SCV), has been introduced to identify high-quality trending broadcasts. SCV incorporates the authority of users, measured by another metric, Social Capital Scores (SCS), who engage with the broadcast based on on-chain data.

For additional information on SCV and SCS, please refer to the following section here.

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:

{% tabs %} {% tab title="npm" %} React

npm install @airstack/airstack-react

Node

npm install @airstack/node

{% endtab %}

{% tab title="yarn" %} React

yarn add @airstack/airstack-react

Node

yarn add @airstack/node

{% endtab %}

{% tab title="pnpm" %} React

pnpm install @airstack/airstack-react

Node

pnpm install @airstack/node

{% endtab %}

{% tab title="pip" %}

pip install airstack

{% endtab %} {% endtabs %}

Then, add the following snippets to your code:

{% tabs %} {% tab title="React" %}

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

{% endtab %}

{% tab title="Node" %}

import { init, fetchQuery } from "@airstack/node";

init("YOUR_AIRSTACK_API_KEY");

const query = `YOUR_QUERY`; // Replace with GraphQL Query

const { data, error } = await fetchQuery(query);

console.log("data:", data);
console.log("error:", error);

{% endtab %}

{% tab title="Python" %}

import asyncio
from airstack.execute_query import AirstackClient

api_client = AirstackClient(api_key="YOUR_AIRSTACK_API_KEY")

query = """YOUR_QUERY""" # Replace with GraphQL Query

async def main():
    execute_query_client = api_client.create_execute_query_object(
        query=query)

    query_response = await execute_query_client.execute_query()
    print(query_response.data)

asyncio.run(main())

{% endtab %} {% endtabs %}

Other Programming Languages

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

Fetch Trending Casts Of Certain Farcaster User

Once you have the criteria, fid, and timeFrame parameters prepared, simply use the query below and add the parameters as variables:

Try Demo

{% embed url="https://app.airstack.xyz/query/91eVe4qncb" %} Show all trending Farcaster casts by FID 602 in the last 1 hour sorted by social capital value {% endembed %}

Code

{% tabs %} {% tab title="Query" %}

query MyQuery(
  $criteria: TrendingCastsCriteria!
  $timeFrame: TrendingCastTimeFrame!
  $fid: Int!
) {
  TrendingCasts(
    input: {
      blockchain: ALL
      criteria: $criteria
      timeFrame: $timeFrame
      filter: { fid: { _eq: $fid } }
    }
  ) {
    TrendingCast {
      criteria
      criteriaCount
      hash
      id
      castValueFormatted
      castValueRaw
      timeFrom
      timeTo
      cast {
        text
        mentions {
          fid
          position
        }
        embeds
        url
      }
    }
  }
}

{% endtab %}

{% tab title="Variables" %}

{
  "timeFrame": "one_hour",
  "criteria": "social_capital_value",
  "fid": 602
}

{% endtab %}

{% tab title="Response" %}

{
  "data": {
    "TrendingCasts": {
      "TrendingCast": [
        {
          "criteria": "social_capital_value",
          "criteriaCount": 354.460477946805,
          "hash": "0x1c22deef09fa4ec2635f8ffc35f19c1149c33a34",
          "id": "0x1c22deef09fa4ec2635f8ffc35f19c1149c33a34",
          "castValueFormatted": 354.460477946805,
          "castValueRaw": "35446047794678",
          "timeFrom": "2024-05-10T16:40:00Z",
          "timeTo": "2024-05-10T17:00:00Z",
          "cast": {
            "text": "we just (permissionlessly) launched the equiv of \n\"onchain credit scores\" for every Farcaster user\n\ndevs: go to town",
            "mentions": [],
            "embeds": [
              {
                "castId": {
                  "fid": 602,
                  "hash": "0x0958f040786e1567c95bb4851056a789616fa576"
                }
              }
            ],
            "url": "https://warpcast.com/betashop.eth/0x1c22deef"
          }
        }
        // Other trending Farcaster casts by FID 602
      ]
    }
  }
}

{% endtab %} {% endtabs %}

🎉 🥳 Congratulations you've just fetched all the trending Farcaster casts of a certain Farcaster user and integrate it into your application!

Developer Support

If you have any questions or need help regarding integrating or building trending casts of a certain user into your application, please join our Airstack's Telegram group.

More Resources