Skip to main content

Farcaster Plugin Developer Guide

Overview

The @elizaos/plugin-farcaster plugin enables elizaOS agents to interact with the Farcaster protocol through the Neynar API. This plugin provides comprehensive functionality for casting, replying, and engaging with the Farcaster ecosystem.

Core Features

1. Casting Capabilities

  • Autonomous Casting: Post original casts based on agent personality
  • Threaded Conversations: Support for reply chains and threads
  • Media Support: Embed images, links, and frames in casts
  • Scheduled Posting: Time-based cast scheduling

2. Engagement Features

  • Reply Detection: Monitor and respond to mentions and replies
  • Like/Recast: Programmatic engagement with other casts
  • Follow Management: Automatic follow/unfollow based on criteria
  • Channel Support: Post to specific channels (e.g., /elizaos)

3. Hub Integration

  • Hub API: Direct integration with Farcaster hubs
  • Message Validation: Cryptographic message signing
  • Protocol Compliance: Full Farcaster protocol v2 support

Installation

Configuration

Environment Variables

Character Configuration

Actions

SEND_CAST

Posts a new cast to Farcaster.

REPLY_TO_CAST

Reply to an existing cast.

Providers

farcasterProfile

Provides the agent’s Farcaster profile information.

farcasterTimeline

Supplies recent timeline casts for context.

Events

handleCastSent

Triggered when a cast is successfully sent. Stores metadata for tracking:

handleMessageReceived

Processes incoming Farcaster messages and creates memories:

Managers

FarcasterAgentManager

Orchestrates all Farcaster operations for an agent:

FarcasterCastManager

Handles autonomous casting based on configuration:

FarcasterInteractionManager

Processes mentions, replies, and interactions:

Services

FarcasterService

Main service coordinating all Farcaster operations:

MessageService

Implements IMessageService for message operations:

CastService

Implements IPostService with full CRUD operations:

Client Architecture

FarcasterClient

Core client wrapping Neynar API operations:

Common Utilities

AsyncQueue

Manages asynchronous operations with concurrency control:

Helper Functions

Event System

Cast Events

Error Events

Memory & Storage

Memory System

The plugin uses elizaOS’s memory system for persistence rather than direct database tables:

Caching Strategy

LRU cache for performance optimization:
  • Cast Cache: TTL 30 minutes, 9000 entries max
  • Profile Cache: User profile data
  • Timeline Cache: Recent timeline casts
  • Last Cast Tracking: Per-agent last cast timestamps

Security Considerations

Key Management

  • Store API keys and signer UUIDs securely using environment variables
  • Never commit credentials to version control
  • Use separate Neynar API keys for development and production
  • Create separate signers for different environments

Rate Limiting

  • Implement exponential backoff for API requests
  • Respect hub rate limits (typically 100 req/min)
  • Cache frequently accessed data

Content Validation

  • Validate cast length (max 320 characters)
  • Sanitize user inputs
  • Verify message signatures

Performance Optimization

AsyncQueue Implementation

The plugin uses an async queue to prevent rate limiting:

Polling Optimization

Troubleshooting

Common Issues

  1. Authentication Errors
    • Verify mnemonic is correct
    • Ensure FID matches the mnemonic
    • Check hub connectivity
  2. Rate Limiting
    • Implement retry logic with backoff
    • Use caching to reduce API calls
    • Monitor rate limit headers
  3. Message Validation Failures
    • Verify timestamp is within valid range
    • Ensure proper message formatting
    • Check signature validity

Debug Mode

Enable debug logging:

Best Practices

  1. Content Strategy
    • Keep casts concise and engaging
    • Use channels appropriately
    • Maintain consistent voice
  2. Engagement Guidelines
    • Don’t spam or over-engage
    • Respect community norms
    • Build genuine connections
  3. Technical Implementation
    • Handle errors gracefully
    • Implement proper retry logic
    • Monitor performance metrics

Migration Guide

From v1 to v2

Support

License

MIT License - see LICENSE file for details