Prerequisites
Before you begin, make sure you have:- Node.js (v20 or higher)
- Git
- A code editor
- Basic knowledge of JavaScript/TypeScript
Helpful Resources
Development Guide
1
Set Up Your Development Environment
Clone the XMTP Agent Examples Repository:
2
Install Dependencies
Install all required packages:
3
Generate Keys for Your Agent
Run the key generation script to create your agent’s wallet:This creates a .env file with:
4
Write Your Agent Logic
Create a basic agent that responds to messages:Then run your agent:
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.Example Implementations
Explore these examples in the/examples
folder:- 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-nft-gated-group: Add members to a group based on an NFT
- xmtp-coinbase-agentkit: Agent that uses a CDP for gassless USDC on base
- xmtp-transactions: Use XMTP content types to send transactions
- xmtp-smart-wallet: Agent that uses a smart wallet to send messages
5
Test Your Agent
Development Testing
- 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
Production Testing
- Update environment:
- Test on Base App:
- Open Base App mobile app
- Go to messaging
- Start conversation with your agent’s address
- Verify functionality
6
Get a Basename for Your Agent
Give your agent a human-readable name:
- Import agent wallet to Base App extension:
- Install Base App browser extension
- Import using your agent’s private key
- 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
- 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…
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
- WALLET_KEY=your_agent_private_key
- 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
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