earth

Send a Basic Cast on Farcaster

April 17, 2025

A cast is Farcaster’s version of a tweet, a short, public message you post to the network. Under the hood, each cast is a signed message that gets submitted to a Farcaster hub.

In this guide, you’ll create a simple text cast, sign it with a signer key, and broadcast it to Farcaster using a hub. Before you begin, make sure you’ve added a signer to your account.

✨ Tip: Casts look more personal when your profile is filled out. If you haven’t already, set your display name, bio, profile picture, and username first.

You can view the complete script on GitHub to copy, customize, or run it end-to-end.

Prepare the Signer

To send a cast, you’ll need to sign it with a key that’s already authorized account. We’ll load the signer’s private key from an environment variable and create a signer instance.

import { hexToBytes, type Hex } from 'viem';
import { NobleEd25519Signer } from '@farcaster/core';

const privateKeyBytes = hexToBytes(process.env.WALLET_SIGNER_PRIVATE_KEY! as Hex);
const signer = new NobleEd25519Signer(privateKeyBytes);

Make sure this signer has already been authorized your FID. If not, follow this guide first.

Create the Cast

The CastAddBody object defines the structure of a cast, which includes the text of your post and optional fields like mentions or embedded links. In this example, we’ll keep it simple and just send a plain text message.

import { CastAddBody, CastType } from '@farcaster/core';

const cast: CastAddBody = {
	type: CastType.CAST,
	text: 'hello, farcaster.',
	mentions: [],
	mentionsPositions: [],
	embeds: [],
	embedsDeprecated: [],
};

We’ll cover more complex casts, like mentions, embeds, and reply chains—in future posts. For now, this is enough to get your first cast live.

Sign and Submit the Cast

Once you’ve created the cast object, the next step is to sign it and send it to a hub to process. We’ll use makeCastAdd() to generate the signed message, then submit it using a simple fetch() call.

import { FarcasterNetwork, makeCastAdd, Message } from '@farcaster/core';

const fid = Number(process.env.WALLET_FID);
const HUB_ENDPOINT = 'https://hub.pinata.cloud';

// Sign the cast message
const message = await makeCastAdd(cast, { fid, network: FarcasterNetwork.MAINNET }, signer);

// Check for errors
if (message.isErr()) throw new Error(message.error.message);

// Encode the message in binary format
const data = Message.encode(message.value).finish();

// Submit the message to a Farcaster hub
const response = await fetch(`${HUB_ENDPOINT}/v1/submitMessage`, {
	method: 'post',
	headers: { 'Content-Type': 'application/octet-stream' },
	body: data,
});

console.log('Hub response:', await response.json());

If the response is successful, your cast has been published and should appear shortly in Farcaster clients like Warpcast.

Next Steps

Congrats, your cast is live! If everything worked correctly, you should see your message appear in clients like Warpcast within a few seconds.

Here’s what you might want to explore next:

Reply to a cast

Casts can include a parentCastId to create replies or threads. We’ll cover that in an upcoming guide.

Mention other users

Tag people in your cast to bring them into the conversation.

Use the embeds field to add rich content like images, mini apps, quoted casts, or urls.

Keep an eye out for future posts where we’ll cover all of these features step by step.