Skip to content

XMTP

XMTP is the protocol that MessageKit uses to send and receive messages.

Check out the XMTP AI plugins for more information.

Context

The Context object is a core component that provides access to all XMTP messaging functionality. It handles conversations, groups, and messages.

import { Context } from "@xmtp/message-kit";
 
onMessage(async (context: Context) => {
  const {
    message, // Current message details
    client, // V3 XMTP client
    v2client, // V2 XMTP client
    conversation, // Current conversation
    group, // Group details if in a group chat
  } = context;
 
  // Your message handling logic
});

Properties

Message

Contains information about the current message:

  • content: The message content
  • sender: Address of message sender
  • sent: Timestamp when message was sent
  • typeId: Type of message
  • client: V3 XMTP client instance
  • v2client: V2 XMTP client instance
  • conversation: Current conversation object with messaging methods

Group (V3 Only)

Group chat information including:

  • members: List of all group members
  • admins: List of group administrators
  • superAdmins: List of group super administrators

Identity

Each messages comes with a sender object that contains the address, name, and avatar of the sender.

interface Member {
  // Unique identifier for the user's inbox
  inboxId: string;
 
  // User's blockchain address (e.g. Ethereum address)
  address: string;
 
  // Array of all addresses associated with this identity
  accountAddresses: string[];
 
  // Array of unique installation identifiers
  installationIds: string[];
}
 
// Example usage
const { sender } = context.message;

Properties:

  • inboxId: A unique identifier for the user's message inbox. This remains consistent across different installations.
  • address: The primary blockchain address associated with the sender. This is typically an Ethereum address.
  • accountAddresses: An array of all blockchain addresses linked to this identity. Users can have multiple addresses associated with their XMTP identity.
  • installationIds: Array of unique identifiers for each installation/device where the user has XMTP enabled.

Clients

MessageKit provides wrapped versions of XMTP clients for easier integration:

import { V2Client, V3Client } from "xmtp";

You can create new client instances using the createClient helper:

import { createClient } from "xmtp";
 
const { v2client } = await createClient({
  // Optional configuration
});

Availability

To check if a user has XMTP enabled:

const { v2, v3 } = await context.xmtp.isOnXMTP(address);

Returns:

  • v2: true if user has XMTP V2 enabled
  • v3: true if user has XMTP V3 enabled