Deploy your agent built with XMTP
This guide covers how to deploy an agent using Railway—a platform many developers prefer for quickly and easily deploying agents. While this tutorial focuses on Railway, you can use any hosting provider that supports Node.js and environment variables.
Alternative platforms include:
- Heroku
- Fly.io
- Render
- Vercel
Want to contribute a guide for another platform? We welcome pull requests!
1. Create a Railway account
Sign up for an account at Railway if you don't already have one.
2. Start a new project
From your Railway dashboard, click New Project and select Empty Project.
3. Import your agent's GitHub repository
Click Deploy from GitHub repo and select the repository that contains your agent code.
4. Configure volume storage
Your XMTP agent will need persistent storage. Add a volume to your container:
-
Navigate to your service settings.
-
Select the Volumes tab.
-
Add a new volume and specify the mount path.
Use this code in your agent to properly connect to the Railway volume:
export const getDbPath = (env: string, suffix: string = "xmtp") => {
//Checks if the environment is a Railway deployment
const volumePath = process.env.RAILWAY_VOLUME_MOUNT_PATH ?? ".data/xmtp";
// Create database directory if it doesn't exist
if (!fs.existsSync(volumePath)) {
fs.mkdirSync(volumePath, { recursive: true });
}
const dbPath = `${volumePath}/${env}-${suffix}.db3`;
return dbPath;
};
Then, specify dbPath
in your client options:
const receiverClient = await Client.create(signer, {
dbEncryptionKey,
env: XMTP_ENV as XmtpEnv,
dbPath: getDbPath(XMTP_ENV),
});
5. Configure environment variables
-
Get the connection string for your database.
-
Add the connection string and any other required environment variables to your service.
6. Deploy your agent
Once all configurations are set, Railway will automatically deploy your agent. You can monitor the deployment process on the Deployments tab.
7. Share your agent (optional)
Consider registering an ENS domain for your agent to make it easy to share and access.
Example Railway deployment
For reference, here's an example Railway deployment of a gm-bot agent.