- Claim and register a new user account.
- Assign a fname and username to the new user account.
- Obtain a
signer_uuidfor the new user account and make changes on Farcaster. - Get an understanding of the entire flow behind the scenes.
What You’ll Need
Prerequisites
- Installation of curl, yarn, and Node.js and npm
- Neynar API key from dev.neynar.com
- App Wallet created in developer portal - Setup Guide
- Funded wallet with ETH on Optimism
New to App Wallets? All onchain operations require a wallet_id. See Managing Onchain Wallets to create your app wallet in the developer portal (self-service!).
Step 1: Claim an account for the new user
To register a new user, you need to claim an account for that user.API Call
Responses
Step 2: Ask the user to sign a message accepting their new Farcaster account
To create a Farcaster account, users must sign a message proving they’re willing to accept the account using a particular wallet address. The user needs to sign a message containing- fid (fetched in the previous step)
- the address that will custody the Farcaster account (connected address on the client/app developer)
- and a deadline until which their signature is valid. (generated by the client/app developer)
Setup project
Install Dependencies
Create the Script
Create a file namedgenerate-required-parameters.js
FID_TO_COLLECT_SIGNATURE_FOR with fid returned from GET - /v2/farcaster/user/fid and NEW_ACCOUNT_MNEMONIC with a new account MNEMONIC.
Execute Script
Run the script to generate the necessary parameters for user registration. Get the FID i.eUNIQUE_FID from Step 1 and pass it on in the following command
Script Output
You’ll receive output containing several values, includingdeadline, requested_user_custody_address, fid, signature
Step 3: Add a managed signer to new account (optional)
If you want to add a managed signer to the new account during registration, you can include signer details in the registration request. This allows your application to manage the account on behalf of the user.Create a Signer
First, create a signer using the Create Signer API:signer_uuid and public_key that you’ll need for the next step.
Generate Signed Key Request Metadata Signature
Use the following script to generate thesigned_key_request_metadata_signature needed for the registration request.
Install Additional Dependencies
signed_key_request_metadata_signature along with the signer_uuid, app_fid, and deadline that you’ll include in the registration request.
Step 4: Ask the user to pick their fname (optional)
Client applications should ask users to pick a username for their Farcaster account. The fname availability API should be used to check if their chosen username is available. The fname should match the following regex -/^[a-z0-9][a-z0-9-]{0,15}$/. Official regex defined in the farcaster/core library
Step 5: Register the User
Construct a POST request with the generated parameters to finalize the user’s registration.Finalize Registration
Required: The
x-wallet-id header is required for account registration. See Managing Onchain Wallets for setup instructions.
