Skip to main content

Content Types

All messages in XMTP are encoded with a content type to ensure interoperability and consistency of experience across the network.

Message payloads are transported as simply a set of bytes. This means they can carry any content type that a developer would want to support, such as plaintext, JSON, or even non-text binary or media content.

The client interface allows new content types to be adopted and put to immediate use without going through a formal process. Clients may choose to adopt those content types if they wish to render those message types, but can also rely on fallback plaintext.

Two predefined content types come bundled with the client SDK:

  1. xmtp.org/text:1.0, which defines a default TextCodec for plaintext content
  2. xtmp.org/composite:1.0, which defines an optional CompositeCodec for multiple content types in a single message

These content types were adopted through the XMTP Improvement Proposal process, which enables a framework for community members to propose standards and achieve consensus around their adoption.

Usage

Specify a content type to enable during client initialization. For example, to enable a fictional "number" type using xmtp-js:

// Adding support for a fictional `xmtp.org/number` content type
import { NumberCodec } from '@xmtp/xmtp-js'
const xmtp = Client.create(wallet, { codecs: [new NumberCodec()] })

Send a message using a specified content type and fallback plaintext. Using xmtp-js:

// Assuming NumberCodec can be used to encode numbers and is
// identified with ContentTypeNumber, we can use it as follows.
conversation.send(3.14, {
contentType: ContentTypeNumber,
contentFallback: '3.14'
})