Before we begin, you can access the source code for this guide on GitHub Gist. Let’s get started!Documentation Index
Fetch the complete documentation index at: https://docs.neynar.com/llms.txt
Use this file to discover all available pages before exploring further.
Creating the webhook
To create a new webhook, head to the neynar dashboard and go to the webhooks tab. Click on the new webhook and enter the details as such:
target_url. To test it out, we can use a service like ngrok to create a public URL that will forward requests to your local server.
Creating the server
Let’s create a simple server that logs out the event. We will be using Bun JavaScript.bun serve index.ts, and run ngrok with ngrok http 3000. Copy the ngrok URL and paste it into the “Target URL” field in the Neynar developer portal.
The webhook will call the target URL every time the selected event occurs. Here, I’ve chosen all the casts created with neynarDC present in the text.
Now the server will log out the event when it is fired. It will look something like this:
Adding DC functionality
Firstly, you need a warpcast API key to send DCs. To get one:- Enable Developer Mode in your Farcaster settings
- Go to the developer tools section in your Farcaster client
- Navigate to the API keys section and create a new API key
<warpcast_api_key> with the api key that you generated from the Warpcast dashboard.
In the request, we need to provide the FID to send the message to, the message body, and an idempotencyKey to retry if the request fails.
For the recipientFid we are using the FID of the author of the cast and the idempotencyKey is a random key generated by uuid which we need to install and import: