Skip to content

Inspired by the workshop provided by the Chainlink, user now can create token via X and it will show up in the marketplace!

License

Notifications You must be signed in to change notification settings

BLTC-520/eliza-X-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TokenAizer - AI Agent for Time Token Creation

TokenAizer is a blockchain-native AI agent that enables users to create time tokens via natural language Twitter posts. Built on ElizaOS, it integrates with the TokenizeAI smart contract on Avalanche Fuji testnet to convert services into tradeable digital assets.

πŸš€ Features

  • Natural Language Processing: Create time tokens using conversational Twitter posts
  • Smart Contract Integration: Direct integration with TokenizeAI ERC1155 contract
  • Avalanche Fuji Support: Built for Avalanche Fuji testnet
  • Twitter Bot: Responds to mentions and processes token creation requests
  • Real-time Validation: Intelligent keyword detection and parameter extraction

πŸ“‹ Prerequisites

  • Node.js v22+
  • pnpm
  • Twitter Developer Account
  • Avalanche Fuji testnet wallet with AVAX
  • Google Gemini API key

πŸ›  Installation

  1. Clone the repository

    git clone <repository-url>
    cd Eliza-Twitter-Chainlink-Functions
  2. Install dependencies

    pnpm install
  3. Configure environment variables

    cp .env.example .env

    Edit .env with your credentials:

    # Google Gemini API
    GEMINI_API_KEY=your_gemini_api_key
    
    # Wallet Configuration
    EVM_PRIVATE_KEY=your_private_key
    ETHEREUM_PROVIDER_AVALANCHEFUJI=your_alchemy_url
    
    # Twitter Configuration
    TWITTER_USERNAME=your_bot_username
    TWITTER_PASSWORD=your_bot_password
    TWITTER_EMAIL=your_bot_email
    
    # Model Override
    LARGE_GOOGLE_MODEL=gemini-1.5-flash
  4. Start the agent

    pnpm start

🎯 Usage

Twitter Integration

Mention the bot on Twitter with a message like:

@YourBotHandle Create token for wallet 0x742d35Cc6573C0532c22bdc9b8c4e3f0e8b5e123, service React Development, price 80 per hour, 40 hours total, valid 60 days

Local Chat

For testing, you can also chat locally after starting the agent.

πŸ— Architecture

Core Components

  • Character: src/character.ts - TokenAizer AI personality and configuration
  • Plugin: src/custom-plugins/index.ts - Main plugin registration
  • Action: src/custom-plugins/actions/createToken.ts - Smart contract interaction logic
  • Template: src/custom-plugins/templates/index.ts - Natural language to JSON conversion
  • Types: src/custom-plugins/types/index.ts - TypeScript interfaces

Smart Contract Integration

  • Contract Address: 0xcEC74F686A7EEC2d818a1646996F3eDc9da890EA
  • Network: Avalanche Fuji Testnet
  • ABI: Located in src/custom-plugins/artifacts/TokenizeAI.json
  • Function: createTimeToken(creator, serviceName, pricePerHour, totalHours, validityDays)

Action Flow

  1. Input Processing: User posts natural language message on Twitter
  2. Validation: validate() function checks for required keywords and patterns
  3. Template Processing: LLM converts natural language to structured JSON parameters
  4. Smart Contract Call: Extracted parameters sent to TokenizeAI contract
  5. Response: Transaction hash returned to user

πŸ”§ Technical Details

Validation Patterns

The action detection uses flexible regex patterns:

  • Wallet: /0x[a-fA-F0-9]{40}/ - Ethereum address format
  • Create Keywords: /create|mint|generate|make|tokenize/ + /token|time.*token/
  • Service Keywords: /service|development|consulting|teaching|tutoring|coding|programming|react|dev/
  • Price: /\$?\d+.*hour|hour.*\$?\d+|price.*\d+/
  • Time: /\d+.*hour|hour.*\d+|valid.*\d+.*day|day.*\d+/

Parameter Extraction

The template system uses GPT to extract:

  • address: Ethereum wallet address (42 characters, starts with '0x')
  • serviceName: Service description string
  • pricePerHour: Price in AVAX (converted to wei)
  • totalHours: Available hours as integer
  • validityDays: Token validity period in days

πŸ› Challenges & Solutions

1. Action Detection Issues

Problem: The validate() function was returning boolean instead of object, causing actions to never trigger.

Solution: Updated validation to return {score: 1.0, name: "CREATE_TOKEN", intent: "CREATE_TOKEN"} as required by ElizaOS runtime.

2. Google Gemini API Quota Limits

Problem: Hit daily and per-minute rate limits for gemini-1.5-pro model.

Solution: Added LARGE_GOOGLE_MODEL=gemini-1.5-flash environment variable to override ElizaOS default model mapping.

3. TypeScript Interface Mismatches

Problem: ElizaOS TypeScript definitions expected boolean return from validate() but runtime required object.

Solution: Used as any type assertion to bypass TypeScript while maintaining correct runtime behavior.

4. Strict Keyword Matching

Problem: Original validation was too restrictive, requiring exact keyword matches that failed with natural language variations.

Solution: Implemented flexible regex patterns for semantic matching (e.g., "react" matches service keywords, "80 per hour" matches price patterns).

5. Blockchain Unit Conversion

Problem: Price values were being sent as raw numbers (80) instead of wei units, resulting in 0.0000 AVAX prices.

Solution: Added parseEther() conversion to transform AVAX amounts to wei before smart contract calls.

6. Plugin Registration

Problem: Custom plugin wasn't being loaded when using CLI with character JSON files.

Solution: Integrated plugin directly in src/index.ts to ensure it's always loaded with the agent runtime.

7. Natural Language Processing

Problem: Converting varied user inputs like "80 per hour for 40 hours valid 60 days" into structured contract parameters.

Solution: Created comprehensive template with examples and validation rules to guide LLM parameter extraction.

πŸ” Debugging

Enable debug logging by checking console output for:

  • πŸ” CREATE_TOKEN validate() called - Action detection
  • 🎯 CREATE_TOKEN validation result - Validation logic breakdown
  • πŸ” DEBUG: Extracted tokenParams - Template extraction results
  • πŸš€ DEBUG: About to call smart contract - Contract call parameters

πŸ“ Example Interactions

Valid Input:

Create token for wallet 0x742d35Cc6573C0532c22bdc9b8c4e3f0e8b5e123, service React Development, price 80 per hour, 40 hours total, valid 60 days

Expected Output:

{
  "address": "0x742d35Cc6573C0532c22bdc9b8c4e3f0e8b5e123",
  "serviceName": "React Development", 
  "pricePerHour": 80,
  "totalHours": 40,
  "validityDays": 60
}

πŸš€ Deployment

For production deployment:

  1. Set TWITTER_DRY_RUN=false
  2. Use production Avalanche network
  3. Configure proper error handling and monitoring
  4. Set up PM2 for process management

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.

πŸ”— Links

About

Inspired by the workshop provided by the Chainlink, user now can create token via X and it will show up in the marketplace!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 27