In part one, you reserved a Farcaster username by submitting a signed claim to the Fname Registry. In this post, you’ll publish that name to your profile by submitting a message to a Farcaster hub.
This step uses your signer key to create and send a message that links your reserved username to your FID. Once submitted, your username will appear in clients like Warpcast and other apps built on Farcaster.
Before you begin, make sure you’ve:
You can view the complete script on GitHub to copy, customize, or run it end-to-end.
To publish activity on Farcaster, you need to sign it with an authorized key and send it to a hub. We’ll use the signer we set up earlier.
Load the signer’s private key from an environment variable, then 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 key belongs to a signer already registered to your FID. If not, add a signer first.
Next, you’ll create a UserDataAdd message that sets your username. This message will be signed with your authorized key and linked to your FID.
import { FarcasterNetwork, makeUserDataAdd, UserDataType } from '@farcaster/core';
const fid = Number(process.env.WALLET_FID);
const username = 'dooloo';
const message = await makeUserDataAdd(
{ type: UserDataType.USERNAME, value: username },
{ fid, network: FarcasterNetwork.MAINNET },
signer
);
console.log(message);
This prepares a signed message that tells the network: “This FID is now using dooloo as its username.” Be sure the username value matches the one you reserved in the previous step.
Once your message is signed, you’ll need to send it to a Farcaster hub. Hubs receive, validate, and broadcast user messages across the network.
You can use any public or self-hosted hub endpoint. We’ll use the public hub generously provided by Pinata.
import { Message } from '@farcaster/core';
const HUB_ENDPOINT = 'https://hub.pinata.cloud';
// Encode the message in binary format
const data = Message.encode(message.value).finish();
// Send the message to the hub
const response = await fetch(`${HUB_ENDPOINT}/v1/submitMessage`, {
method: 'post',
headers: { 'Content-Type': 'application/octet-stream' },
body: data,
});
console.log(await response.json());
If the submission is successful, your username will be linked to your FID and visible in Farcaster clients like Warpcast.
Your username is now linked to your FID and should appear in clients like Warpcast shortly after the hub processes your message.
Here’s what you might want to do next:
Use a client like Warpcast to confirm your username appears correctly.
Use the same pattern to set a bio, display name, or profile picture with additional UserDataAdd messages.