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.
- 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
- Node.js v22+
- pnpm
- Twitter Developer Account
- Avalanche Fuji testnet wallet with AVAX
- Google Gemini API key
-
Clone the repository
git clone <repository-url> cd Eliza-Twitter-Chainlink-Functions
-
Install dependencies
pnpm install
-
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
-
Start the agent
pnpm start
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
For testing, you can also chat locally after starting the agent.
- 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
- Contract Address:
0xcEC74F686A7EEC2d818a1646996F3eDc9da890EA
- Network: Avalanche Fuji Testnet
- ABI: Located in
src/custom-plugins/artifacts/TokenizeAI.json
- Function:
createTimeToken(creator, serviceName, pricePerHour, totalHours, validityDays)
- Input Processing: User posts natural language message on Twitter
- Validation:
validate()
function checks for required keywords and patterns - Template Processing: LLM converts natural language to structured JSON parameters
- Smart Contract Call: Extracted parameters sent to TokenizeAI contract
- Response: Transaction hash returned to user
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+/
The template system uses GPT to extract:
address
: Ethereum wallet address (42 characters, starts with '0x')serviceName
: Service description stringpricePerHour
: Price in AVAX (converted to wei)totalHours
: Available hours as integervalidityDays
: Token validity period in days
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.
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.
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.
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).
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.
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.
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.
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
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
}
For production deployment:
- Set
TWITTER_DRY_RUN=false
- Use production Avalanche network
- Configure proper error handling and monitoring
- Set up PM2 for process management
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.