Create a .env file. Load it into process.env before you call Agent.createFromEnv(). The SDK does not read the file itself:
Terminal window
XMTP_BACKEND_URL=https://your-backend.example.com
XMTP_WALLET_KEY=0x...
XMTP_DB_ENCRYPTION_KEY=0x...
XMTP_ENV=my-app
XMTP_BACKEND_URL is required and must include its scheme. XMTP_ENV is only a label for a directory under the storage root. The wallet key must use 0x hex format. The database encryption key is 32 bytes.
Create an agent from XMTP_* variables. XMTP_BACKEND_URL overrides options.backend; one must be supplied. Pass backend.credentials in options for backend authentication.
Adds the listener function to the end of the listeners array for the
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The
emitter.prependListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
Adds the listener function to the end of the listeners array for the
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The
emitter.prependListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
Start conversation and message streams. Calling this while running is a no-op.
start();
Agent.createFromEnv() creates the client and registers its installation. agent.start() starts message and conversation readers. The start event means that the local readers are ready. The backend can still be offline.
Use Node.js 22.12.0 or later. A minimal container image must include CA certificates for an HTTPS backend.