Write Data with Managed Signers
Write to Farcaster protocol and let Neynar manage your signers for you
If using login providers like Privy, it’s best to use this signer product.
Users won’t see a double login and developers will get full write functionality to Farcaster.
In this guide, we’ll take a look at how to integrate neynar managed signers with neynar in a next.js app so your users can take actions on the Farcaster protocol. Managed signers allow you to take full control of the connection, including the branding on Warpcast and everything else!
To get started immediately, you can clone this GitHub repository
Run the app as per the readme page in the repo
Context
This guide covers setting up a Next.js backend server to create and use Neynar Managed Signers for publishing a cast on Farcaster. The backend will:
- Create a signer for the user.
- Generate signature.
- Provide API routes for frontend interactions.
- Allow publishing casts on behalf of authenticated users.
You can integrate this backend with a compatible frontend to enable a seamless authentication and authorization flow using Neynar Managed Signers.
The ideal user flow
Terminology
To understand the ideal user flow, let’s quickly go over some terminology:
- Authentication: This is where an account proves they are who they say they are. Flows like Sign in with Farcaster (SIWF) or login providers like Privy allow this for app logins.
- Authorization: this is where an account gives the app certain access privileges to take actions on behalf of the account. This is what Neynar signers allow for writing data to the protocol.
Authorization requires authentication so that once a user is authenticated, they can then authorize an action. E.g. authenticating into your Google account to then authorize a 3rd party app like Slack to access your Google Calendar. If starting logged out, the full flow takes two distinct steps.
User journey
You can build a user flow using tools like:
- SIWN: Connect Farcaster accounts
- or 3rd party login providers like Privy
If using Privy
- the 1st step on authentication happens on Privy login and the 2nd step of authorization happens on Neynar
- the second step requires the user to scan a QR code or tap on a link to then generate a signer on a Farcaster client like Warpcast. Generating a signer requires paying onchain fees
- Neynar sponsors signers by default so users pay $0.
Let’s go!
Now that we have context, let’s get started!
Requirements
- Node.js (LTS recommended)
Installation
-
Next.js
-
Dependencies (to install via
npm
,yarn
, etc.): -
Environment Variables: Create a
.env.local
file in your Next.js project root and add:- NEYNAR_API_KEY: Get from Neynar Dashboard.
- FARCASTER_DEVELOPER_MNEMONIC: The mnemonic for your developer account on Farcaster. e.g.
@your_company_name
account on Farcaster (to state the obvious out loud, you won’t need user mnemonics at any point)
Directory Structure
Make the following directory structure in your codebase
1. lib/neynarClient.ts
Copy the following into a file called lib/neynarClient.ts
2. utils/getFid.ts
Copy the following code into a file called utils/getFid.ts
3. utils/getSignedKey.ts
Copy the following code into a file called utils/getSignedKey.ts
We are doing a couple of things here, so let’s break it down.
We first use the createSigner
to create a signer, and then we use the appAccountKey.signKeyRequest
function from the @farcaster/hub-nodejs
package to create a sign key request. Finally, we use the registerSignedKey
function from the neynarClient to register the signedKey. registerSignedKey
returns signer_approved_url
that needs to be handled (More on this in step 7)
4. app/api/signer/route.ts
Copy the following code into app/api/signer/route.ts
5. app/api/cast/route.ts
Copy the following code into app/api/cast/route.ts
6. Run the app
Make sure nothing is running on port 3000. Ensure that your .env.local
file is correctly set up before running the application.
Now, the app is ready to serve requests. You can build a frontend to handle these requests, but for this demo, we’ll use cURL.
7. cURL /api/signer
Response
You can either store the signer_uuid
in the database or use fetchSigners api to fetch signers for the user (We recommend the latter method)
Convert signer_approved_url
to a QR code (For testing, you can use any online tool, e.g., QRFY)
If the user is using the application on desktop, then ask the user to scan this QR code. If the user is on mobile, ask them to click the link. This will deeplink the user into Warpcast, and they will see the following screenshot.
The user will need to pay for this on-chain transaction. (If you don’t want users to pay, you can sponsor it yourself or let neynar sponsor the signer)
8. cURL /api/cast
Response
Conclusion
With this backend setup, your Next.js app can:
- Generate Neynar Managed Signers for a single app. (
@your_company_name
account) - Provide API routes for frontend interactions to handle signers and publishing casts.
This backend should be integrated with the corresponding frontend to enable a seamless login and cast publishing experience.
For the completed code with frontend intergation, check out the GitHub repository.
If you encounter any issues, reach out to the Neynar team for support.
Was this page helpful?