Documentation Index
Fetch the complete documentation index at: https://mintlify.com/matrix-org/matrix-js-sdk/llms.txt
Use this file to discover all available pages before exploring further.
Overview
createClient is the recommended entry point for instantiating a MatrixClient. Unlike calling new MatrixClient() directly, it automatically provisions default implementations for the store, scheduler, and cryptoStore dependencies when they are not supplied.
src/matrix.ts:148
Function Signature
Configuration options. All properties of
ICreateClientOpts are passed directly to the MatrixClient constructor.A new, fully configured
MatrixClient instance. Call startClient() to begin syncing.ICreateClientOpts Reference
Connection
The base URL of the homeserver, e.g.
"https://matrix.org". Must not have a trailing slash.The base URL of the identity server, e.g.
"https://vector.im".A custom
fetch implementation. Falls back to the global fetch if not provided.Default maximum time in milliseconds to wait before timing out HTTP requests. No timeout by default.
Send the access token as an
Authorization: Bearer header rather than a query parameter. Default: true. Note: query-parameter access tokens are deprecated as of Matrix spec v1.11.Extra query parameters appended to all requests. Useful for application services that require
?user_id=.Authentication
The access token for the user’s session. Required for most API calls.
An OIDC refresh token, if applicable. Used by
tokenRefreshFunction to renew accessToken.A callback invoked by the HTTP layer when a potentially expired token is encountered and a
refreshToken is available.The MXID of the logged-in user, e.g.
"@alice:matrix.org". Required for most authenticated operations.A unique identifier for this device. Required to enable end-to-end encryption. Must be consistent across sessions for the same device.
Storage
The sync data store. If not specified,
createClient provisions a MemoryStore (with localStorage in browsers). To persist data across sessions use IndexedDBStore.A store for end-to-end crypto session data.
createClient uses the factory registered via setCryptoStoreFactory(), or a MemoryCryptoStore if no factory is set. Required when migrating a device from legacy crypto to Rust crypto.An encryption key used to protect sensitive data (e.g. E2EE keys) in the
cryptoStore. Must be the same value every time the client is initialised for the same device. Only used by the legacy crypto implementation.Scheduling
The event scheduler. If not specified,
createClient creates a default MatrixScheduler. Without a scheduler, failed requests will not be retried.Cryptography
Application-provided callbacks for cryptographic operations, such as prompting the user for cross-signing keys or secret storage passphrases.
The interactive verification methods to offer when verifying another device. If unset, all known methods (QR code display, QR code scan, SAS/emojis) are offered.
Enable encrypted state events (experimental).
Identity Server
A provider object with a
getAccessToken() method. Used to authenticate calls to the identity server without manually managing identity server access tokens.Timeline
Enable improved timeline support, required for
getEventTimeline(). Disabled by default for compatibility with older clients. Set to true for modern applications.Room Display
A callback to generate room names for empty or membership-derived room names. Defaults to a built-in English handler with basic pluralisation.
VoIP / Group Calls
Force all WebRTC calls to relay through a TURN server. Default:
false.Number of ICE candidates to gather on incoming call before signalling begins. Default:
0.Advertise support for call transfers. Default:
false.Allow a fallback ICE server when the homeserver provides none. Default:
false.Encrypt to-device signalling for group calls with Olm. Default:
true.Use LiveKit media at the application layer instead of the built-in WebRTC stack. Group calls will only create signalling events.
Allow joining group calls without an active media stream. Default:
false.Disable VoIP support entirely (prevents fetching TURN servers, etc.). Default:
false.Logging
A custom logger for this
MatrixClient instance. Defaults to the global logger. Use DebugLogger for verbose output.Usage Examples
- Minimal (TypeScript)
- Minimal (JavaScript)
With a persistent store
- TypeScript
- JavaScript
With Rust Crypto (E2EE)
- TypeScript
- JavaScript
createRoomWidgetClient()
Construct a MatrixClient that operates inside a Matrix widget. This client communicates with the host client via the Matrix Widget API rather than directly with a homeserver, and therefore has a restricted feature set.
src/matrix.ts:166
The
WidgetApi instance from matrix-widget-api used for communication between the widget and the host client.The capabilities the widget client will request from the host client.
The ID of the room the widget is associated with.
Standard client options (at minimum
baseUrl).Whether to send a
ContentLoaded widget action immediately after setup. Set to false if waitForIFrameLoad=true is used, or if the widget wants to send ContentLoaded at a later time. Default: true.A
RoomWidgetClient instance (subclass of MatrixClient) with restricted capabilities.