A comprehensive plugin for ElizaOS that enables AI agents to fully participate in the Farcaster social network with posting, replying, and engagement capabilities.
The ElizaOS Farcaster Plugin provides a complete integration with Farcaster, allowing AI agents to:
- Post & Reply: Create original casts and reply to conversations
- Monitor Mentions: Track and respond to mentions automatically
- Engage with Content: Like, recast, and interact with other users' posts
- Context-Aware Responses: Maintain conversation threads and context
- Real-time Interaction: Process interactions in real-time with configurable intervals
This plugin leverages the Neynar API and implements full ElizaOS service interfaces for seamless integration.
- FarcasterService: Main service managing agent connections and lifecycle
- MessageService: Implements
IMessageServicefor sending/receiving messages - CastService: Implements
IPostServicefor creating and managing casts
- SEND_CAST: Post casts based on user requests
- REPLY_TO_CAST: Reply to existing casts with context
- farcasterProfile: Provides agent's Farcaster profile information
- farcasterTimeline: Supplies recent timeline casts for context
- Automated Posting: Schedule and publish regular casts
- Engagement Monitoring: Track mentions and interactions
- Conversation Threading: Maintain conversation context
- Metadata Tracking: Store cast metadata for reference
- Health Monitoring: Built-in health check functionality
- Caching: Efficient caching for improved performance
npm install @elizaos/plugin-farcaster- Create a Farcaster Account: If you don't have one, sign up at Warpcast
- Note your FID: Find your Farcaster ID in your profile settings
- Get Neynar API Access:
- Sign up at Neynar Developer Portal
- Create a new application
- Copy your API key
- Create a Signer:
- In the Neynar dashboard, go to "Signers"
- Create a new signer for your FID
- Copy the Signer UUID
Copy the example environment file and fill in your credentials:
cp env.example .envEdit .env with your credentials:
FARCASTER_FID=your-fid-here
FARCASTER_NEYNAR_API_KEY=your-api-key-here
FARCASTER_SIGNER_UUID=your-signer-uuid-here
FARCASTER_MODE=polling # or 'webhook' for real-time processingFor real-time interaction processing instead of polling, you can configure webhooks:
FARCASTER_MODE=webhookIf running locally, use ngrok to expose your server:
# Install ngrok if you haven't already
npm install -g ngrok
# Expose your local server (default port 3000)
ngrok http 3000This will give you a URL like: https://c7120f641530.ngrok-free.app
- Go to Neynar Webhook Dashboard
- Click "New webhook"
- Set the Target URL to:
https://your-ngrok-url.ngrok-free.app/farcaster/webhook- Example:
https://c7120f641530.ngrok-free.app/farcaster/webhook
- Example:
- Configure Event Types:
- Select
cast.created
- Select
- Set Filters:
- Mentioned users: Add your Farcaster username
- Parent cast authors: Add your Farcaster username
Once configured, your agent will receive real-time notifications when:
- Someone mentions your agent
- Someone replies to your agent's casts
The plugin requires the following configurations, which can be set via environment variables or ElizaOS runtime settings:
| Parameter | Description |
|---|---|
FARCASTER_NEYNAR_API_KEY |
Neynar API key for accessing Farcaster |
FARCASTER_SIGNER_UUID |
Signer UUID for your Farcaster account |
FARCASTER_FID |
Your Farcaster FID (identifier) |
FARCASTER_MODE |
Interaction mode: polling or webhook |
| Parameter | Description | Default |
|---|---|---|
FARCASTER_DRY_RUN |
Run in simulation mode without posting (true/false) | false |
MAX_CAST_LENGTH |
Maximum length of casts | 320 |
FARCASTER_POLL_INTERVAL |
Interval for checking mentions (minutes) | 2 |
ENABLE_CAST |
Enable automatic casting (true/false) | true |
CAST_INTERVAL_MIN |
Minimum time between casts (minutes) | 90 |
CAST_INTERVAL_MAX |
Maximum time between casts (minutes) | 180 |
ENABLE_ACTION_PROCESSING |
Enable processing interactions (true/false) | false |
ACTION_INTERVAL |
Interval for processing actions (minutes) | 5 |
CAST_IMMEDIATELY |
Cast immediately on startup (true/false) | false |
MAX_ACTIONS_PROCESSING |
Maximum actions to process in one cycle | 1 |
ACTION_TIMELINE_TYPE |
Type of timeline to use for actions | ForYou |
- In your agent's character file:
{
"name": "MyFarcasterAgent",
"bio": "An AI agent on Farcaster",
"plugins": ["@elizaos/plugin-farcaster"],
"settings": {
"FARCASTER_FID": "123456",
"FARCASTER_NEYNAR_API_KEY": "your-api-key",
"FARCASTER_SIGNER_UUID": "your-signer-uuid",
"FARCASTER_MODE": "webhook"
}
}- Start your agent:
elizaos start --character path/to/character.jsonThe plugin provides actions that can be triggered through natural language:
User: "Can you post about the new ElizaOS features on Farcaster?"
Agent: "I'll post about the new ElizaOS features on Farcaster now."
[Agent posts to Farcaster]
User: "Reply to that cast and thank them for the feedback"
Agent: "I'll reply with a thank you message."
[Agent replies to the cast]
import farcasterPlugin from '@elizaos/plugin-farcaster';
// The plugin exports its components
const { actions, providers, services } = farcasterPlugin;
// Access specific services programmatically
const farcasterService = runtime.getService('farcaster');
const messageService = farcasterService.getMessageService(agentId);
const castService = farcasterService.getCastService(agentId);You can customize the templates used for generating casts by providing custom templates in your agent character configuration:
const myCharacter = {
name: 'My Agent',
bio: 'A helpful AI assistant on Farcaster',
templates: {
farcasterPostTemplate: `
# Custom post template
Write a thoughtful post about {{topic}} in the voice of {{agentName}}.
`,
farcasterMessageHandlerTemplate: `
# Custom reply template
Respond to {{currentPost}} as {{agentName}} would.
`,
farcasterShouldRespondTemplate: `
# Custom response decision template
Determine if {{agentName}} should respond to {{currentPost}}.
`,
},
};npm run buildnpm testnpm run devThe plugin is organized into several core components:
- FarcasterService: Main service managing agent lifecycle and health monitoring
- MessageService: Handles sending/receiving messages, implements
IMessageService - CastService: Manages casts and interactions, implements
IPostService
- FarcasterClient: Base client for Neynar API interactions
- FarcasterAgentManager: Manages agent-specific connections
- FarcasterInteractionManager: Handles mentions and replies
- FarcasterCastManager: Manages autonomous casting
- Actions: User-triggered capabilities (SEND_CAST, REPLY_TO_CAST)
- Providers: Context providers for agent awareness
- Event Handlers: Metadata tracking and event processing
The plugin includes comprehensive test coverage:
Located in __tests__/unit/:
- Service functionality tests
- Action validation tests
- Provider output tests
Located in __tests__/e2e/:
- Real account interactions
- Full conversation flows
- Error handling scenarios
# Run all tests
npm test
# Run unit tests only
npm run test:unit
# Run E2E tests (requires API keys)
npm run test:e2e
# Run with coverage
npm run test:coverageFor E2E tests, ensure your .env file contains valid API credentials.
- @neynar/nodejs-sdk: Official SDK for Neynar API
- @elizaos/core: ElizaOS core framework
- lru-cache: Efficient caching
- zod: Schema validation
Contributions are welcome! Please ensure all tests pass and add new tests for any new functionality.
This plugin is part of the ElizaOS ecosystem and follows the same licensing terms.