Write casts to channel

Write casts to 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.

Got a dank meme you want to share with Farcaster? This guide demonstrates how to use the Neynar SDK to post a cast to a channel.

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

Before all that, initialize Neynar 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);
const signer = process.env.NEYNAR_SIGNER;

Poast meme to 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 memeUrl = "https://i.imgur.com/cniMfvm.jpeg";

const result = await client.publishCast(signer, "me irl", {
  embeds: [{ url: memeUrl }],
  replyTo: memesChannelUrl,
});

Example output:

{
  hash: "0xccabe27a04b1a63a7a24a035b0ffc2a2629e1af1",
  author: {
    object: "user",
    fid: 4640,
    custody_address: "0x86dd7e4af49829b895d24ea2ab581c7c32e87332",
    username: "picture",
    display_name: "Picture",
    pfp_url: "https://lh3.googleusercontent.com/erYudyT5dg9E_esk8I1kqB4bUJjWAmlNu4VRnv9iUuq_by7QjoDtZzj_mjPqel4NYQnvqYr1R54m9Oxp9moHQkierpY8KcYLxyIJ",
    profile: {
      bio: [Object ...]
    },
    follower_count: 45,
    following_count: 124,
    verifications: [],
    active_status: "inactive"
  },
  text: "me irl"
}

There you go, make sure to share your good memes with the Farcaster!

🚀

Ready to start building?

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