Public
Like
farcaster-autoPostToX
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v21View latest version
This Val Town script automatically cross-posts your Farcaster casts to Twitter/X using webhooks. When you create a new cast on Farcaster, it gets automatically posted to your Twitter account.
- Receives Farcaster webhooks: Listens for
cast.createdevents from Neynar - Filters content: Only processes original casts (skips replies/responses)
- Handles media: Downloads images from Farcaster and uploads them to Twitter
- Manages text length: Ensures posts stay within Twitter's 280-character limit
- Cross-posts: Automatically posts your Farcaster content to Twitter/X
- ✅ Automatic cross-posting from Farcaster to Twitter
- ✅ Image support (up to 2 images per post)
- ✅ URL preservation in posts
- ✅ Character limit validation
- ✅ Error handling and logging
- ✅ Skips replies to avoid spam
- Fork this Val Town script to your account
- Note your Val's URL (you'll need this for the webhook setup)
- Go to Twitter Developer Portal
- Create a developer account if you don't have one
- Create a new app/project
Before generating your access tokens, you must configure user authentication:
- In your Twitter app settings, go to "User authentication settings"
- Set up OAuth 1.0a with Read and Write permissions
- Add your website URL and callback URL (can be placeholder URLs)
- Save the settings
After setting up authentication with read/write permissions:
- Go to "Keys and Tokens" tab
- Generate/copy these credentials:
- API Key (
TWITTER_API_KEY) - API Secret (
TWITTER_API_SECRET) - Access Token (
TWITTER_ACCESS_TOKEN) - Access Token Secret (
TWITTER_ACCESS_TOKEN_SECRET)
- API Key (
Note: Free plan limits: 100 posts read + 500 writes per month
In your Val Town script, add these environment variables:
TWITTER_API_KEYTWITTER_API_SECRETTWITTER_ACCESS_TOKENTWITTER_ACCESS_TOKEN_SECRET
- Go to Neynar Webhook Setup
- Create a new webhook with these settings:
- Event Type:
cast.created - Target URL: Your Val Town script URL (e.g.,
https://yourname-scriptname.web.val.run) - Filter: Configure to only receive your own casts (set your FID)
- Event Type:
Note: Neynar webhooks require a paid plan
- You create a cast on Farcaster
- Neynar sends a webhook to your Val Town script
- The script processes the cast:
- Skips if it's a reply
- Downloads any images and uploads them to Twitter
- Appends non-image URLs to the text
- Validates character count
- Posts the content to Twitter/X automatically
- Twitter Free Plan: 100 reads + 500 writes per month
- Neynar webhooks require paid subscription
- Maximum 2 images per post (Farcaster limit)
- 280 character limit for Twitter posts
- Only processes original casts (not replies)
Check the Val Town logs if posts aren't appearing on Twitter:
- Verify all environment variables are set
- Ensure Twitter API keys have read/write permissions
- Check that webhook URL is correctly configured in Neynar
- Verify your Neynar webhook is active and properly filtered
For issues with:
- Twitter API: Check Twitter Developer Documentation
- Neynar Webhooks: Check Neynar Documentation
- Val Town: Check Val Town Documentation