This is a serverless function that handles Neynar webhook events and automatically calls a protected TrueCast API using CDP wallet payments, deployed on Vercel.
- Receives Neynar webhook events for cast.created
- Automatically creates CDP smart account for payments
- Calls protected x402 TrueCast API with automatic payment handling
- Handles payment authentication using viem and x402-axios
- CDP API credentials (API Key ID, Secret, and Wallet Secret)
- A deployed x402-next-standalone TrueCast API
- Vercel account for deployment
-
Install dependencies:
cd neynar-webhook npm install -
Install Vercel CLI (if not already installed):
npm i -g vercel
-
Deploy to Vercel:
vercel
Follow the prompts:
- Link to existing project? → No
- What's your project's name? →
neynar-webhook-handler(or your preferred name) - In which directory is your code located? →
./(current directory)
-
Set Environment Variables: See
env-variables.mdfor required environment variables that must be set in your Vercel project settings. -
Get your webhook URL: After deployment, Vercel will provide you with a URL like:
https://your-project-name.vercel.app/api/webhook
- Go to the Neynar Developer Dashboard
- Navigate to the Webhooks tab
- Create a new webhook with:
- Target URL:
https://your-project-name.vercel.app/api/webhook - Event Type:
cast.created - Filters:
mentioned_fids: Add your bot's FID (to get notified when tagged)parent_author_fids: Add your bot's FID (to get notified when someone replies)
- Target URL:
You can test locally by running:
vercel devThis will start a local development server at http://localhost:3000
- View logs in the Vercel dashboard
- Check the Functions tab to see invocations and errors
- Use
console.logstatements in your webhook handler to debug
- Webhook Receipt: Receives
cast.createdevents from Neynar - CDP Wallet Creation: Automatically creates or retrieves a CDP smart account
- Payment Processing: Uses x402-axios to handle payment authentication
- API Call: Calls the protected TrueCast API with the cast data
- Response Handling: Logs the response and returns success/error status
The webhook automatically processes all cast.created events. You can modify api/webhook.js to:
- Add filtering logic for specific mentions or keywords
- Process additional webhook event types
- Add custom response handling
- Integrate with other services after successful API calls
- The function always returns a 200 status to prevent webhook retries
- As recommended by Neynar docs, avoid using ngrok or similar tunneling services
- Use your own domain or Vercel's provided URLs for reliable webhook delivery