Fetching casts from Memes channel in Farcaster

Show casts from a Farcaster channel with Neynar

Channels are "subreddits inside Farcaster." Technically, a channel is a collection of casts that share a common parent_url. For example, the memes channel is a collection of casts that share the parent_url chain://eip155:1/erc721:0xfd8427165df67df6d7fd689ae67c8ebf56d9ca61.

This guide demonstrates how to use the Neynar SDK to fetch casts from a channel.

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 feed in memes channel.

πŸ“˜

channel_name to parent_url mapping

All parent_url to channel_name mappings can be found at this Github repo, along with other channel metadata.

This repo is open source so feel free to submit PRs for additional channel data if you see anything missing.

const memesChannelUrl =
  "chain://eip155:1/erc721:0xfd8427165df67df6d7fd689ae67c8ebf56d9ca61";

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

console.log(feed);

Example output:

{
  casts: [
    {
      object: "cast_hydrated",
      hash: "0xf17168571d5e403f3b608ea2cc09a0b711d4c4fc",
      thread_hash: "0xf17168571d5e403f3b608ea2cc09a0b711d4c4fc",
      parent_hash: null,
      parent_url: "chain://eip155:1/erc721:0xfd8427165df67df6d7fd689ae67c8ebf56d9ca61",
      parent_author: [Object ...],
      author: [Object ...],
      text: "",
      timestamp: "2023-11-27T14:40:12.000Z",
      embeds: [
        [Object ...]
      ],
      reactions: [Object ...],
      replies: [Object ...],
      mentioned_profiles: []
    }, {
      object: "cast_hydrated",
      hash: "0x344dcd9c7c2671450628aacd0bbb8e29ea2e8809",
      thread_hash: "0x344dcd9c7c2671450628aacd0bbb8e29ea2e8809",
      parent_hash: null,
      parent_url: "chain://eip155:1/erc721:0xfd8427165df67df6d7fd689ae67c8ebf56d9ca61",
      parent_author: [Object ...],
      author: [Object ...],
      text: "sorry",
      timestamp: "2023-11-27T14:24:32.000Z",
      embeds: [
        [Object ...]
      ],
      reactions: [Object ...],
      replies: [Object ...],
      mentioned_profiles: []
    }, {
      object: "cast_hydrated",
      hash: "0x68b94ec2a10ebad8b13e3b673f0db02dd3280f42",
      thread_hash: "0x68b94ec2a10ebad8b13e3b673f0db02dd3280f42",
      parent_hash: null,
      parent_url: "chain://eip155:1/erc721:0xfd8427165df67df6d7fd689ae67c8ebf56d9ca61",
      parent_author: [Object ...],
      author: [Object ...],
      text: "man today is such a nice morning",
      timestamp: "2023-11-27T13:30:11.000Z",
      embeds: [
        [Object ...]
      ],
      reactions: [Object ...],
      replies: [Object ...],
      mentioned_profiles: []
    }
  ],
  next: {
    cursor: "eyJ0aW1lc3RhbXAiOiIyMDIzLTExLTI3IDEzOjMwOjExLjAwMDAwMDAifQ=="
  }
}

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

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

There you go! You now know how to fetch casts from a Farcaster channel with Neynar SDK.

πŸš€

Ready to start building?

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