Created
April 11, 2025 21:16
-
-
Save alongcamewayne/533dc5007368372e91371a25905975f5 to your computer and use it in GitHub Desktop.
Script to set the display name for your Farcaster account. https://dololand.com/set-farcaster-display-name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Set a Farcaster display name by submitting a signed message to a hub. | |
| * | |
| * This script: | |
| * - Loads an authorized signer key | |
| * - Creates a UserDataAdd message to set the display name | |
| * - Signs and submits the message to a Farcaster hub | |
| * | |
| * Requirements: | |
| * - A registered FID | |
| * - An authorized signer (already added to the FID) | |
| * | |
| * .env: | |
| * WALLET_FID=1234 | |
| * WALLET_SIGNER_PRIVATE_KEY="0x..." (hex-encoded Ed25519 private key) | |
| */ | |
| import { hexToBytes, type Hex } from 'viem'; | |
| import { | |
| FarcasterNetwork, | |
| makeUserDataAdd, | |
| Message, | |
| NobleEd25519Signer, | |
| UserDataType, | |
| } from '@farcaster/core'; | |
| const HUB_ENDPOINT = 'https://hub.pinata.cloud'; // Public Farcaster hub endpoint | |
| const fid = Number(process.env.WALLET_FID); | |
| // Load the authorized signer from the environment | |
| const privateKeyBytes = hexToBytes(process.env.WALLET_SIGNER_PRIVATE_KEY! as Hex); | |
| const signer = new NobleEd25519Signer(privateKeyBytes); | |
| // Define the display name you'd like to set | |
| const displayName = 'dr. dooloo'; | |
| // Create a signed UserDataAdd message to set the display name | |
| const message = await makeUserDataAdd( | |
| { type: UserDataType.DISPLAY, value: displayName }, | |
| { fid, network: FarcasterNetwork.MAINNET }, | |
| signer | |
| ); | |
| console.log('Signed message:', message); | |
| // Encode the message to binary format before submission | |
| const data = Message.encode(message.value).finish(); | |
| // Submit the message to the hub | |
| const response = await fetch(`${HUB_ENDPOINT}/v1/submitMessage`, { | |
| method: 'post', | |
| headers: { 'Content-Type': 'application/octet-stream' }, | |
| body: data, | |
| }); | |
| // Log the hub's response | |
| console.log('Hub response:', await response.json()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment