Trending feed on Farcaster

Show casts trending on the Farcaster network through Neynar

This guide demonstrates how to use the Neynar SDK to get trending casts on Farcaster.

Check out this Getting started guide to learn how to set up your environment and get an API key.

First, initialize the client:

// npm i @neynar/nodejs-sdk
import { NeynarAPIClient, FeedType, FilterType } from "@neynar/nodejs-sdk";

// make sure to set your NEYNAR_API_KEY .env
// don't have an API key yet? get one at neynar.com
const client = new NeynarAPIClient(process.env.NEYNAR_API_KEY);

Then fetch the global trending Farcaster casts:

const feed = await client.fetchFeed(FeedType.Filter, {
  filterType: FilterType.GlobalTrending,
});

console.log(feed);

Example output:

{
  casts: [
    {
      object: "cast_hydrated",
      hash: "0xa3194378e37b6d9f738c079d7a374e7ffce3eb46",
      thread_hash: "0xa3194378e37b6d9f738c079d7a374e7ffce3eb46",
      parent_hash: null,
      parent_url: "chain://eip155:1/erc721:0x9c8ff314c9bc7f6e59a9d9225fb22946427edc03",
      parent_author: [Object ...],
      author: [Object ...],
      text: "Noob question: why are nouns called nouns? Does each one have a particular noun (in English or some other language) attached?",
      timestamp: "2023-11-26T14:17:49.000Z",
      embeds: [],
      reactions: [Object ...],
      replies: [Object ...],
      mentioned_profiles: []
    }, {
      object: "cast_hydrated",
      hash: "0xc64ebefd8ebc83d8e6c88f49f10274fb3251937e",
      thread_hash: "0xc64ebefd8ebc83d8e6c88f49f10274fb3251937e",
      parent_hash: null,
      parent_url: "chain://eip155:7777777/erc721:0xc2a1570703480b72091283decb80292c273db559",
      parent_author: [Object ...],
      author: [Object ...],
      text: "Explain this chart in one word.",
      timestamp: "2023-11-26T23:03:25.000Z",
      embeds: [
        [Object ...]
      ],
      reactions: [Object ...],
      replies: [Object ...],
      mentioned_profiles: []
    }, {
      object: "cast_hydrated",
      hash: "0x9a027e0f825efa1f030298ff5354f71cc03cd87a",
      thread_hash: "0x9a027e0f825efa1f030298ff5354f71cc03cd87a",
      parent_hash: null,
      parent_url: "chain://eip155:8453/erc721:0xe7a43b5942f15fddeb9733fdcc57c6232f1d5aa0",
      parent_author: [Object ...],
      author: [Object ...],
      text: "teaching myself generative art, proud of this one\n\nhaving art that can literally live on the blockchain as code is much more appealing than uploading a GIF to IPFS or some image storage system",
      timestamp: "2023-11-26T22:15:23.000Z",
      embeds: [
        [Object ...]
      ],
      reactions: [Object ...],
      replies: [Object ...],
      mentioned_profiles: []
    }
  ],
  next: {
    cursor: "eyJ0aW1lc3RhbXAiOiIyMDIzLTExLTI2IDIyOjE1OjIzLjAwMDAwMDAiLCJwb2ludHMiOiIxMzYifQ=="
  }
}

To fetch the next page of the feed, use the cursor:

const nextFeed = await client.fetchFeed(FeedType.Filter, {
  filterType: FilterType.GlobalTrending,
  cursor: feed.next.cursor,
});

It's that easy to get trending casts in Farcaster!

🚀

Ready to start building?

Get your subscription at neynar.com and reach out to us on Telegram with any questions!