earth

Reply to a Cast on Farcaster

April 17, 2025

Replies on Farcaster work just like regular casts but with one key addition: a parentCastId. This field tells the network which cast you’re responding to, enabling threaded conversations and reply chains.

If you haven’t already sent a cast, check out Send a Cast on Farcaster first. You’ll also need a signer authorized for your FID. Here’s how to add one if you’re not set up yet.

Script

import { hexToBytes, type Hex } from 'viem';
import {
	CastAddBody,
	CastType,
	FarcasterNetwork,
	makeCastAdd,
	Message,
	NobleEd25519Signer,
} from '@farcaster/core';

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

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

// Define your reply
const cast: CastAddBody = {
	type: CastType.CAST,
	text: 'is this thing on?',
	parentCastId: {
		fid,
		hash: hexToBytes('0x010c5ac8656bd4c0cd42081f7c0b9c381c1ed06c'), // hash of the cast you're replying to
	},
	mentions: [],
	mentionsPositions: [],
	embeds: [],
	embedsDeprecated: [],
};

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

if (message.isErr()) throw new Error(message.error.message);

const data = Message.encode(message.value).finish();

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

console.log(await response.json());

Replies will appear threaded under the original cast in clients like Warpcast. You can reply to any cast, not just your own,as long as you have the cast’s hash and caster’s fid.

Next Steps

Want to build rich conversations? Combine replies with mentions and embeds.