Skip to main content
Build powerful chat agents that integrate seamlessly with Base App using the XMTP messaging protocol.
For the complete guide, visit XMTP documentation

Installation

npm install @xmtp/agent-sdk

Usage

This example shows how to create an agent that sends a message when it receives a text message.
[Node]
import { Agent } from '@xmtp/agent-sdk';

// 2. Spin up the agent
const agent = await Agent.createFromEnv({
  env: 'production', // base app works only on production
});

// 3. Respond to text messages
agent.on('text', async (ctx) => {
  await ctx.sendText('Hello from my Base App Agent! 👋');
});

// 4. Log when we're ready
agent.on('start', () => {
  console.log(`Waiting for messages...`);
  console.log(`Address: ${agent.address}`);
});

await agent.start();

Set environment variables

To run an example XMTP agent, you must create a .env file with the following variables:
XMTP_WALLET_KEY= # the private key of the wallet
XMTP_DB_ENCRYPTION_KEY= # encryption key for the local database
XMTP_ENV=production # local, dev, production

Get a basename for your agent

Give your agent a human-readable name: 1. Import agent wallet to Base App extension: • 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…
For the complete guide, visit XMTP documentation