Getting started
This guide will walk you through creating, testing, and deploying your first XMTP messaging agent. By the end, you’ll have a fully functional agent that can send and receive messages on the XMTP messaging network. Prerequisites• Node.js (v20 or higher)
• Git
• A code editor
• Basic knowledge of JavaScript/TypeScript Resources STEP 1: SET UP YOUR DEVELOPMENT ENVIRONMENT Clone the XMTP Agent Examples Repository:
Getting the address of a user
Each user has a unique inboxId for retrieving their associated addresses (identifiers). One inboxId can have multiple identifiers like passkeys or EVM wallet addresses./examples
folder, including:
- xmtp-gm: A simple agent that replies to all text messages with “gm”
- xmtp-gpt: An example using GPT API’s to answer messages
- xmtp-gated-group: Add members to a group based on arbitrary criteria
- xmtp-coinbase-agentkit: Agent that uses a CDP for gasless USDC on base
- xmtp-transactions: Allow transactions between users and agents
- xmtp-gaia: Agent that uses a CDP for gasless USDC on base
- xmtp-smart-wallet: Agent that uses a smart wallet to send messages
- xmtp-attachments: Agent that sends and receives images
- xmtp-inline-actions: An example using inline actions (dynamic buttons)
- xmtp-thinking-reaction: Agent that reacts to messages with a thinking emoji
- xmtp-queue-dual-client: Agent that uses two clients to send and receive messages
- xmtp-welcome-message: Agent that sends a welcome message when its added and to new members
- Start your agent:
- Test on xmtp.chat:
• Go to https://xmtp.chat
• Connect your personal wallet
• Switch to Dev environment in settings
• Start a new conversation with your agent’s public address (from .env)
• Send a test message and verify the agent responds
- Update environment:
- Test on Base App:
• Open Base App mobile app
• Go to messaging
• Start conversation with your agent’s address
• Verify functionality
• Install Base App browser extension
• Import using your agent’s private key 2. Purchase a basename:
• Visit https://base.org/names
• Connect your agent’s wallet
• Search and purchase your desired basename (e.g., myagent.base.eth)
• Set as primary name 3. Verify setup:
• Your agent can now be reached via the basename instead of the long address
• Users can message myagent.base.eth instead of 0x123… STEP 7: DEPLOY YOUR AGENT Option 1: Railway (Recommended) • Visit https://railway.app
• Connect your GitHub repository
• Add environment variables in Railway dashboard:
- XMTP_ENV=production
- XMTP_WALLET_KEY=your_agent_private_key
- XMTP_DB_ENCRYPTION_KEY=your_agent_encryption_key • Deploy and monitor logs Option 2: Other Platforms
Heroku, Vercel, or any Node.js hosting platform:
• Ensure your package.json has the correct start script
• Set environment variables in your hosting platform
• Deploy your repository STEP 8: MONITOR AND MAINTAIN Best Practices
- Logging: Add comprehensive logging to track agent activity
- Error Handling: Implement try-catch blocks for network issues
- Rate Limiting: Respect XMTP rate limits in your agent logic
- Security: Never expose private keys; use environment variables