Castorix is a Rust command-line interface and library for Farcaster builders. It keeps your custody wallets encrypted, generates Basenames/ENS username proofs, registers Ed25519 signers, pulls Hub data, and stays in sync with Snapchain β all from one toolchain.
Get up and running in 5 minutes:
# 1. Clone and setup
git clone https://github.com/RyanKung/castorix.git
cd castorix
cp env.example .env
# 2. Edit .env with your API keys
# ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/your-key
# FARCASTER_HUB_URL=https://hub-api.neynar.com
# 3. Build and install
cargo build
cargo install --path .
# 4. Create your first encrypted wallet
castorix key generate-encrypted my-wallet "My Main Wallet"
# 5. Create an ENS username proof
castorix ens create yourname.eth 12345 --wallet-name my-wallet
# 6. Submit to Farcaster Hub
castorix hub submit-proof ./proof_yourname_eth_12345.json 12345 --wallet-name my-walletNeed help? Check out the examples directory or jump to the CLI Quick Tour.
- π Encrypted key vault β interactive flows keep ECDSA custody wallets under
~/.castorix/keys - π·οΈ Basename & ENS proofs β resolve domains, audit Base subdomains, and mint Farcaster-ready username proofs
- π‘ Hub power tools β fetch user graphs, storage stats, custody addresses, casts, and push proof submissions
- βοΈ Signer management β generate Ed25519 keys, register/unregister with dry-run previews, and export safely
- π¨ Spam intelligence β optional labels from the
merkle-team/labelsdataset bundled as a submodule - π€ MCP Server β expose Farcaster query tools to AI assistants (22 tools for Claude Desktop and more)
- π§© All-in-one workspace β Farcaster contract bindings, helper binaries, and a Snapchain node live in the repo
.
βββ src/ # CLI entry points, Farcaster client, key managers
β βββ cli/ # Command-line interface and handlers
β βββ farcaster/ # Farcaster protocol integration
β βββ ens_proof/ # ENS domain proof generation
β βββ key_manager.rs # Encrypted key management
β βββ main.rs # Application entry point
βββ tests/ # Integration tests (many expect a local Anvil node)
βββ examples/ # Example binaries and demos
β βββ basic_key_management.rs
β βββ ens_proof_creation.rs
β βββ README.md
βββ contracts/ # Solidity contracts, scripts, Foundry config
β βββ src/ # Smart contract source code
β βββ script/ # Deployment scripts
β βββ test/ # Contract tests
βββ snapchain/ # Snapchain Rust node (see snapchain/README.md)
βββ labels/labels/ # Spam label dataset for hub spam tooling
βββ generated_abis/ # Generated contract ABIs
βββ proto/ # Protocol buffer definitions
βββ env.example # Environment configuration template
βββ README.md
- π¦ Rust 1.70+ β Install via rustup
- π§± Cargo β Comes with Rust
- π Ethereum RPC endpoint β Get free API keys from Alchemy or Infura
- π°οΈ Farcaster Hub endpoint β Use Neynar's public hub (free tier available)
- π οΈ Foundry's Anvil β For local development (
cargo install --locked foundry-cli) - ποΈ Git submodules β For spam detection features (
git submodule update --init --recursive) - π¦ Protocol Buffers compiler β For advanced features (
brew install protobuf)
- Memory: 8GB+ RAM recommended
- Storage: 1GB+ free space
- Network: Stable internet connection for RPC calls
git clone https://github.com/RyanKung/castorix.git
cd castorixgit submodule update --init --recursive # required for spam detection featurescp env.example .env # copy configuration template
# Edit .env with your API keys and endpointscargo build # build the CLI and librarycargo install --path . # install castorix command globally- Development: Use
cargo run -- <subcommand>to run commands - Production: After global install, use
castorix <subcommand>directly
cargo run -- --help # or castorix --help if installed globallyCopy env.example to .env and customize the values:
cp env.example .env
# Edit .env with your configuration# Main Ethereum network (required for ENS operations)
ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/your-api-key
# Base chain (required for .base.eth domains)
ETH_BASE_RPC_URL=https://mainnet.base.org
# Optimism (required for Farcaster contracts)
ETH_OP_RPC_URL=https://mainnet.optimism.io# Farcaster Hub endpoint (default: Neynar public hub)
FARCASTER_HUB_URL=https://hub-api.neynar.comCastorix supports two key management modes:
# Generate a new encrypted key
castorix key generate-encrypted my-wallet "My Main Wallet"
# Load the key for operations
castorix key load my-wallet# Set private key in environment (insecure)
PRIVATE_KEY=0x1234567890abcdef...- Encrypted keys:
~/.castorix/keys/ - Custody wallets:
~/.castorix/custody/ - Ed25519 signers:
~/.castorix/ed25519/ - Configuration:
~/.castorix/config/
Note: During development, prefix commands with
cargo run --. After global installation, usecastorixdirectly.
castorix --help # Show all available commands
castorix key --help # Show key management commands
castorix ens --help # Show ENS-related commands
castorix hub --help # Show Farcaster Hub commands# Generate a new encrypted wallet
castorix key generate-encrypted my-wallet "My Main Wallet"
# Import an existing private key securely
castorix key import backup-key "Backup Wallet" 0x1234...
# List all your encrypted keys
castorix key list
# Load a key for operations
castorix key load my-wallet
# Get information about the loaded key
castorix key info# Sign a message with the loaded key
castorix key sign "Hello, Farcaster!"
# Verify a signature
castorix key verify <signature> "Hello, Farcaster!"
# Rename a key
castorix key rename old-name new-name
# Update key alias/description
castorix key update-alias my-wallet "Updated Description"
# Delete a key (permanent!)
castorix key delete my-wallet# Generate plain-text key (insecure)
castorix key generateCustody wallets are used for managing Farcaster identities and signer registration.
# List all stored custody wallets
castorix custody list
# Import custody private key for a specific FID
castorix custody import 12345
# Derive custody key from recovery mnemonic
castorix custody from-mnemonic 12345
# Delete custody wallet for a FID
castorix custody delete 12345Storage: Custody wallets are encrypted and stored in
~/.castorix/custody/
# Resolve an ENS domain to address
castorix ens resolve vitalik.eth
# Get all ENS domains for an address
castorix ens domains 0x1234567890abcdef...
# Get all domains (comprehensive lookup)
castorix ens all-domains 0x1234567890abcdef...
# Verify domain ownership
castorix ens verify mydomain.eth# Get Base subdomains for an address
castorix ens base-subdomains 0x1234567890abcdef...
# Check specific Base subdomain
castorix ens check-base-subdomain name.base.eth
# Query Base contract directly
castorix ens query-base-contract name.base.eth# Create a username proof for Farcaster
castorix ens create mydomain.eth 12345 --wallet-name my-wallet
# Verify a proof file
castorix ens verify-proof ./proof_mydomain_eth_12345.jsonOutput: Proof files are saved as
proof_<domain>_<fid>.json
# Get basic user information
castorix hub user 12345
# Get detailed user profile
castorix hub profile 12345
# Get profile with all metadata
castorix hub profile 12345 --all# Get user's followers
castorix hub followers 12345
# Get followers with limit
castorix hub followers 12345 --limit 50
# Get users that this FID follows
castorix hub following 12345# Get Ethereum addresses for a FID
castorix hub eth-addresses 12345
# Get ENS domains for a FID
castorix hub ens-domains 12345
# Get custody address for a FID
castorix hub custody-address 12345# Get hub information
castorix hub info
# Get storage statistics for a FID
castorix hub stats 12345# Check if FID is marked as spam
castorix hub spam 12345
# Get spam statistics
castorix hub spam-stat# Get recent casts by FID
castorix hub casts 12345
# Get specific number of casts
castorix hub casts 12345 --limit 10
# Get all casts (may take time)
castorix hub casts 12345 --limit 0
# View full JSON structure
castorix hub casts 12345 --limit 5 --jsonDisplays:
- β° Timestamp (formatted UTC)
- π Cast hash (unique ID)
- π Signer (Ed25519 public key)
- π Text content
- π Number of embeds
- π₯ Number of mentions
# Submit username proof to hub
castorix hub submit-proof ./proof.json 12345 --wallet-name my-wallet
# Submit EIP-712 signed proof
castorix hub submit-proof-eip712 ./proof.json --wallet-name my-walletNote:
hub castandhub verify-ethcommands are currently under development.
Ed25519 signers are used for signing Farcaster messages and content.
# List all signers for a FID
castorix signers list
# Get detailed signer information
castorix signers info 12345# Register a new signer (with dry-run preview)
castorix signers register 12345 --wallet my-custody --payment-wallet my-key --dry-run
# Register signer (live transaction)
castorix signers register 12345 --wallet my-custody --payment-wallet my-key
# Unregister a signer
castorix signers unregister 12345 --wallet my-custody --payment-wallet my-key --dry-run# Export signer by index or public key
castorix signers export 0
castorix signers export 0x1234...
# Delete signer
castorix signers delete 0
castorix signers delete 0x1234...Dry Run: Use
--dry-runto preview transactions without executing them. Generated signers are encrypted and stored in~/.castorix/ed25519/.
Castorix includes a traditional RESTful HTTP API server for web and application integrations.
# Start on default port (3000)
castorix api serve
# Start on custom port
castorix api serve --port 8080
# Start on specific host
castorix api serve --host 127.0.0.1 --port 3000Health Check:
GET /health- Server status
Hub Endpoints:
GET /api/hub/users/:fid- Get user information βGET /api/hub/users/:fid/profile- Get detailed profileGET /api/hub/users/:fid/stats- Get user statisticsGET /api/hub/users/:fid/followers- Get followers listGET /api/hub/users/:fid/following- Get following listGET /api/hub/users/:fid/addresses- Get ETH addressesGET /api/hub/users/:fid/ens- Get ENS domainsGET /api/hub/users/:fid/custody- Get custody addressGET /api/hub/users/:fid/casts- Get user castsGET /api/hub/spam/:fid- Check spam status βGET /api/hub/info- Get hub information
ENS Endpoints (requires ETH_RPC_URL):
GET /api/ens/resolve/:domain- Resolve ENS domainGET /api/ens/verify/:domain/:address- Verify ownership
Contract Endpoints (requires ETH_OP_RPC_URL):
GET /api/contract/fid/price- Get FID registration price βGET /api/contract/storage/price/:units- Get storage price βGET /api/contract/address/:address/fid- Check address FID β
# Check server health
curl http://localhost:3000/health
# Get user information
curl http://localhost:3000/api/hub/users/3
# Check spam status
curl http://localhost:3000/api/hub/spam/12345
# Get FID registration price
curl http://localhost:3000/api/contract/fid/priceIMPORTANT: The REST API is READ-ONLY and NEVER touches private keys:
- β Safe to expose to the internet
- β
FarcasterClient initialized with
None(no key manager) - β All endpoints are GET requests (query-only)
- β No signing operations
- β No transaction broadcasting
- β No private key access
All sensitive operations (signing, transactions) are CLI-only and require explicit user interaction.
Castorix includes a Model Context Protocol server that exposes Farcaster query capabilities to AI assistants.
# Start MCP server (communicates via stdio)
castorix mcp serveHub Queries (12)
hub_get_user- Get user information by FIDhub_get_profile- Get detailed profilehub_get_stats- Get user statisticshub_get_followers- Get followers listhub_get_following- Get following listhub_get_eth_addresses- Get verified Ethereum addresseshub_get_custody_address- Get custody addresshub_get_info- Get Hub sync statushub_get_ens_domains- Get verified ENS domainshub_check_spam- Check spam statushub_get_spam_stats- Get spam statisticshub_get_casts- Get user posts/casts
ENS Tools (3)
ens_resolve_domain- Resolve ENS domain to addressens_check_base_subdomain- Check Base subdomainens_verify_ownership- Verify domain ownership
Contract Queries (4)
fid_get_price- Get FID registration coststorage_get_price- Get storage rental pricefid_check_address- Check if address has FIDstorage_check_units- Check storage units
Signer & Custody (3)
signers_list_local- List local Ed25519 keyssigners_get_info- Get signer infocustody_list_local- List custody keys
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"castorix": {
"command": "/path/to/castorix",
"args": ["mcp", "serve"],
"env": {
"FARCASTER_HUB_URL": "https://hub-api.neynar.com",
"ETH_RPC_URL": "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY",
"ETH_BASE_RPC_URL": "https://mainnet.base.org",
"ETH_OP_RPC_URL": "https://mainnet.optimism.io"
}
}
}
}- "Tell me about FID 3"
- "Show me @dwr's latest 10 casts"
- "What Ethereum addresses does FID 3 have?"
- "Resolve vitalik.eth"
- "Is FID 12345 spam?"
- "How much does FID registration cost?"
Note: The MCP server communicates via JSON-RPC 2.0 over stdio and is compatible with any MCP-compatible AI assistant.
# Start local Anvil node (Optimism fork)
cargo start-node
# Stop local Anvil node
cargo stop-node
# Check node status
curl http://127.0.0.1:8545# Run basic key management example
cargo run --example basic_key_management
# Run ENS proof creation example
cargo run --example ens_proof_creationMost integration tests require a local Optimism fork and specific environment setup.
# Install Foundry (required for Anvil)
cargo install --locked foundry-cli
# Initialize git submodules for spam detection tests
git submodule update --init --recursive# Start local Anvil node (Optimism fork)
cargo start-node
# Run tests with test environment flag
RUNNING_TESTS=1 cargo test
# Stop the local node
cargo stop-node- Unit tests:
cargo test(no external dependencies) - Integration tests:
RUNNING_TESTS=1 cargo test(requires Anvil) - External API tests: May fail without proper API keys
Note: Some tests require external RPC endpoints and may be skipped if prerequisites aren't available.
The snapchain/ directory contains a complete Rust implementation of Farcaster's Snapchain data layer.
Snapchain is a decentralized data storage layer for the Farcaster protocol, providing:
- High Throughput: 10,000+ transactions per second
- Data Availability: Real-time access to user data
- Canonical Implementation: Reference implementation for the protocol
# Navigate to snapchain directory
cd snapchain
# Follow the setup guide
cat README.md
# Start a node (requires Docker)
./snapchain.sh startNote: The Castorix CLI doesn't require Snapchain unless you're running your own node or contributing to the protocol implementation.
# Solution 1: Use encrypted key management (recommended)
castorix key generate-encrypted my-wallet "My Wallet"
castorix key load my-wallet
# Solution 2: Set PRIVATE_KEY environment variable (legacy)
export PRIVATE_KEY=0x1234...# Check your .env file
cat .env | grep ETH_RPC_URL
# Verify API key is valid
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
$ETH_RPC_URL# Ensure proper permissions for castorix directory
chmod 700 ~/.castorix/
chmod 600 ~/.castorix/keys/*# Check if domain exists
castorix ens resolve your-domain.eth
# Verify you own the domain
castorix ens verify your-domain.eth# Ensure Anvil is running
cargo start-node
# Check if ports are available
lsof -i :8545
# Run with verbose output
RUST_LOG=debug RUNNING_TESTS=1 cargo test- π Check the examples directory for usage patterns
- π Report issues on GitHub Issues
- π¬ Join discussions in GitHub Discussions
- π Hub Casting:
castorix hub castandhub verify-ethcommands are under development - π Proof Submission: Username proof submission requires hub-side Ed25519 signer support
- ποΈ Spam Detection: Requires
git submodule update --init --recursiveforlabels/labels/spam.jsonl - β½ Gas Costs: Many operations interact with mainnet contracts β monitor gas costs
- π Rate Limits: Respect RPC provider rate limits for production usage
- π Enhanced Hub Integration: Full protobuf support for casting and verification
- π Hardware Wallet Support: Integration with Ledger and other hardware wallets
- π± Mobile Support: CLI optimizations for mobile development workflows
- π― Advanced Proof Types: Support for additional proof formats and verification methods
- π Analytics Dashboard: Built-in analytics for Farcaster data insights
We welcome contributions! Please see contracts/CONTRIBUTING.md for guidelines.
We welcome contributions from developers of all skill levels!
- Read the guidelines: Start with contracts/CONTRIBUTING.md
- Open an issue: Discuss large changes before implementing
- Fork and branch: Create a feature branch from
main - Test thoroughly: Ensure all tests pass
- Submit PR: Include a clear description of changes
- π§ Bug fixes: Report and fix issues
- π Documentation: Improve guides and examples
- π Features: Add new functionality
- π§ͺ Tests: Improve test coverage
- π¨ UI/UX: Enhance CLI experience
- Follow Rust conventions and
cargo fmt - Add documentation for public APIs
- Include tests for new features
- Update README for significant changes
Castorix ships under the GPL-2.0 License. See LICENSE for the legalese.
