TopGit
GitHub Repo Review

Matrix JavaScript SDK: Client-Server Library for JS

matrix-org/matrix-js-sdk
MTopGit review image for matrix-org/matrix-js-sdk
Review by Topgit.dev for matrix-org/matrix-js-sdk, with GitHub repository stats and README context.
Quick verdict

Matrix JavaScript SDK is the official TypeScript library that Element's own web and desktop apps use to talk to the Matrix protocol. It wraps the Client-Server HTTP API, keeps a live /sync event stream, and exposes Room and User objects instead of raw JSON. Reach for it when building a real Matrix client in Node.js or a browser; skip it for a single scripted message, since standing up sync and crypto there is overkill.

Stars
★ 2.2k
Forks
⑂ 710
Language
TypeScript
License
Apache-2.0
Topic
—
Updated
Oct 2026
Homepage
GitHub

What is the Matrix JavaScript SDK?

Matrix JavaScript SDK is the client-server SDK for the Matrix protocol, written in TypeScript and usable as both a Matrix Node.js SDK and a Matrix browser SDK depending on where you import it. It wraps the Matrix Client-Server API into an object model — Room, RoomMember, User — and emits events for syncing, typing, membership changes, and incoming messages, maintained by Element for its own web and desktop clients.

Who is this SDK for?

Matrix JavaScript SDK fits developers building a decentralized messaging or collaboration client on the Matrix protocol who don't want to hand-roll /sync polling, room state tracking, or the Rust-backed crypto stack themselves. As a Matrix client SDK it suits both browser apps, via Webpack or Vite, and Node.js backends or bots, per the README's supported-platforms list — Element itself builds its web and desktop clients on it. Skip it if you're not targeting Matrix, or need a client for a language other than JavaScript/TypeScript, since this library only covers the JS/TS side of the protocol.

Core Capabilities of the SDK

  • ✓Wraps the full Matrix Client-Server API into an object model — Rooms, RoomState, RoomMembers, and Users — and emits events when any of them change, per the README.
  • ✓Handles /sync polling, pagination, and room initial sync on accepting an invite, so you don't poll the HTTP API by hand.
  • ✓Local echo shows your outgoing message in the timeline right away, tagged as still sending, until the server confirms it — so there's no visible gap between clicking send and the message actually landing.
  • ✓Automatically retries sends on network errors and on rate-limiting errors, and marks messages that ultimately fail as not sent, per the README.
  • ✓End-to-end encryption runs through initRustCrypto(), which loads the WebAssembly bindings of the Rust matrix-sdk-crypto library rather than a JS-only crypto implementation.
  • ✓Covers the harder crypto workflows out of the box: secret storage bootstrap, cross-signing setup, key backup, and device verification, all exposed through the CryptoApi interface.
  • ✓Ships separate entry points for crypto (matrix-js-sdk/lib/crypto-api), spec-level types (matrix-js-sdk/lib/types), and MSC4108 QR-code login and rendezvous (matrix-js-sdk/lib/rendezvous), so you import only what you need.
  • ✓Handles authenticated media downloads and thumbnails via mxcUrlToHttp plus a bearer Authorization header, for servers implementing MSC3916 (Matrix 1.11).
How this repository's GitHub stars have grown over time. Source: star-history.com.View the star history ↗

Getting Started with Installation

Matrix JavaScript SDK installs with a single command: pnpm add matrix-js-sdk — the README suggests pnpm over npm, linking out to pnpm's own installation guide for anyone who doesn't have it set up yet. Once installed, import * as sdk from "matrix-js-sdk" and call sdk.createClient({ baseUrl: "https://matrix.org" }) to get a MatrixClient instance pointed at a homeserver. The minimum Matrix server version the SDK targets is v1.1, and the README flags upfront that some servers require an Authorization header for media downloads, so check the authenticated-media notes before going further. From there, client.startClient({ initialSyncLimit: 10 }) starts the sync loop that populates rooms and timelines.

Building with the SDK: Code Examples

Send a message with client.sendEvent(roomId, "m.room.message", { body: "message text", msgtype: "m.text" }, "", callback), then listen for it with client.on(RoomEvent.Timeline, (event, room, toStartOfTimeline) => { ... }), filtering on event.getType() === "m.room.message". For connection state, client.on(ClientEvent.sync, (state) => { ... }) reports when the client reaches the PREPARED state after its first sync, while RoomMemberEvent.Typing and RoomStateEvent.Members cover typing indicators and membership lists. The default store is an in-memory MemoryStore that holds events as they arrive, so client.store.rooms gives you the cached timeline per room without another round trip to the server. For encryption, await matrixClient.initRustCrypto() turns on the Rust-backed crypto stack before you call matrixClient.getCrypto() for cross-signing, secret storage, or key backup.

Strengths

  • ✓Backed by Element, whose own web and desktop clients run on this exact SDK — the maintainers are also its heaviest daily users.
  • ✓End-to-end encryption uses the same Rust matrix-sdk-crypto engine, via WebAssembly, as Matrix's other official SDKs, instead of a separate JS-only crypto implementation to keep in sync.
  • ✓Covers the unglamorous state-tracking work — local echo, retry on rate limits and network errors, message queueing, pagination — that you'd otherwise write yourself against the raw HTTP API.
  • ✓Apache-2.0 licensed, with no proprietary strings attached.
  • ✓Ships focused entry points (crypto-api, types, rendezvous, testing) so you import just the pieces you need instead of one monolithic bundle.

Important Considerations and Limitations

  • △The crypto stack is explicitly documented as not thread-safe: pointing multiple MatrixClient instances at the same IndexedDB store risks corrupting data and breaking decryption, so it's on the app layer to guarantee only one instance runs at a time.
  • △Switching an app from the old crypto implementation over to Rust crypto isn't a flag flip: you still pass the old cryptoStore and pickleKey into createClient, and the README notes many deprecated MatrixClient methods aren't supported once you're on Rust crypto.
  • △Without a persistent IndexedDB store (i.e. running server-side with useIndexedDB: false), the README says you need to log in as a new device every time the application restarts.
  • △The README admits the primary entry point still carries a lot of leftover code that needs tidying up, so the top-level API surface isn't uniformly clean.
  • △The README warns that authenticated media support is moving from optional to mandatory — a future version will only return URLs that require the Authorization header, a breaking behavior change to plan for.
  • △Deno support exists via import npm:matrix-js-sdk but the README flags it as not officially supported.

Exploring Other Matrix SDKs

Frequently Asked Questions

What platforms does Matrix JavaScript SDK support?

Matrix JavaScript SDK runs in Node.js (the latest LTS release) and in browsers via a bundler like Webpack or Vite. The README also lists Deno support through import npm:matrix-js-sdk, though it flags Deno as not officially supported.

Does Matrix JavaScript SDK support end-to-end encryption?

Matrix JavaScript SDK does support end-to-end encryption, through initRustCrypto(), which loads WebAssembly bindings of the Rust matrix-sdk-crypto library instead of a JavaScript-only implementation. It also covers secret storage, cross-signing, and key backup via the CryptoApi interface.

What is the minimum Matrix server version required?

The README lists v1.1 as the minimum Matrix server version for Matrix JavaScript SDK. A feature later removed from the spec still gets SDK support for at least 4 more releases after removal, under the README's own compatibility guarantee.

How do I migrate from legacy crypto to Rust crypto in the SDK?

Call initRustCrypto() instead of initLegacyCrypto() on Matrix JavaScript SDK, passing the existing cryptoStore and pickleKey into createClient — the migration then runs automatically. Track progress via the CryptoEvent.LegacyCryptoStoreMigrationProgress event, which signals done when progress and total both equal -1.

What license is the Matrix JavaScript SDK released under?

Matrix JavaScript SDK is released under the Apache-2.0 license, per its GitHub repository.

How does the SDK handle authenticated media downloads?

Matrix JavaScript SDK exposes mxcUrlToHttp() to turn an mxc:// URI into a download or thumbnail URL, then expects a bearer Authorization header built from client.getAccessToken() for servers that require it under MSC3916 (Matrix 1.11). The README warns a future version will only return URLs that require this header.

The problem it solves

Chat application development on Matrix's federated network means hand-rolling /sync polling for real-time communication, tracking room and member state across dozens of event types, retrying on rate limits, and now integrating a WebAssembly-backed crypto stack for end-to-end encryption — all before a single line of chat UI gets written. Matrix JavaScript SDK exists because Element needed exactly that stack for its own web and desktop clients and open-sourced the result instead of leaving every Matrix client author to rebuild sync, state tracking, and Rust-crypto bindings independently.

Best use cases

  • •Building a web-based Matrix chat client with a bundler like Webpack or Vite, using the SDK's Room and RoomMember object model instead of parsing /sync responses by hand.
  • •Writing a Node.js Matrix bot or bridge that listens on RoomEvent.Timeline for incoming messages and replies via sendEvent, with automatic retry on rate-limit errors.
  • •Adding end-to-end encryption to a Matrix client via initRustCrypto(), including cross-signing device verification and key backup, without reimplementing the Rust crypto bindings yourself.
  • •Migrating an existing client off the legacy crypto stack onto Rust crypto, tracked through the CryptoEvent.LegacyCryptoStoreMigrationProgress event.
  • •Prototyping against a Matrix homeserver in Deno, though the README flags that path as unofficial.

Related repositories

Source & attribution

Facts and quotes sourced from the matrix-org/matrix-js-sdk GitHub repository and its README.

GitHub data · last synced Aug 12, 2026Reviewed by Henry
← Back to TopGit

Is matrix-js-sdk worth your time?

ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of matrix-js-sdk.

GitHub