Follow the example code while reading the guide for better understanding
Prerequisites
- A browser with a wallet extension (e.g., MetaMask, Coinbase, etc.) installed.
- Access to the Farcaster API and ID Registry smart contract.
- Familiarity with JavaScript and Ethereum wallet interactions.
- App Wallet with
wallet_id- Required for FID fetching. See Managing Onchain Wallets to create one in the developer portal.
New to Wallet IDs? The
/v2/farcaster/user/fid endpoint requires a x-wallet-id header to cover the costs of FID registration. Create your app wallet in the Developer Portal first!Step 1: Connect a Wallet
To connect a wallet in the browser:- Check if the browser supports
window.ethereum. - Use
eth_requestAccountsto request wallet connection.
Code Example:
Step 2: Switch to the Optimism Network
To interact with the ID Registry contract, ensure the wallet is on the Optimism network.Code Example:
Step 3: Fetch FID
Use theGET-/v2/farcaster/user/fid endpoint to retrieve the FID of the account that will be transferred to the wallet’s address. This endpoint requires a x-wallet-id header.
Code Example:
Step 4: Generate signTypedData with Viem
To generate a signature for FID registration:
- Fetch the nonce from the ID Registry contract.
- Create EIP-712 typed data and request a signature from the wallet.
Code Example:
Step 5: Check fname Availability
Before registering a username, check if it is available using the GET /v2/farcaster/fname/availability endpoint.
Code Example:
Step 6: Call the POST-/v2/farcaster/user Endpoint
Submit the required data to create the Farcaster account. This endpoint also requires a x-wallet-id header.

