Library / SDK
matrix-org/matrix-js-sdk avatar
matrix-org/matrix-js-sdk

matrix-js-sdk: an object model over the Matrix Client-Server API, with local echo, retries and a 4-spec-release support window

Matrix Client-Server SDK for JavaScript

2,202 stars718 forksTypeScriptApache-2.0

At a glance

What is it?
matrix-org/matrix-js-sdk is the JavaScript and TypeScript client SDK that Element builds its web and desktop clients on. This review covers the quickstart, the event model, authenticated media, the version policy, and the toolchain you meet when contributing.
Who is it for?
Use matrix-js-sdk if you are building a Matrix client or bot in Node.js 22 or newer, or in a bundled browser app, and you want syncing, timelines and retries handled for you. Skip it if you need a promise that every feature of a given Matrix spec release is implemented, because the README explicitly gives none.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 1 day ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • matrix-org/matrix-js-sdk2,202 ★ · +17
Star history
Repository2026-10-082026-11-25
matrix-org/matrix-js-sdk2.2k2.2k

17 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

A client created with createClient and a baseUrl is the whole entry point

The quickstart installs with pnpm, which the README recommends over npm:

`pnpm add matrix-js-sdk`

The first call builds a client and asks the server for its public rooms:

javascript
import * as sdk from "matrix-js-sdk";
const client = sdk.createClient({ baseUrl: "https://matrix.org" });
client.publicRooms(function (err, data) {
    console.log("Public Rooms: %s", JSON.stringify(data));
});

The baseUrl option names the homeserver. Everything else, including login and sync, hangs off the returned client. The same package runs in Node.js and in a browser, and for the browser the README says to use a bundler such as Webpack or Vite.

Deno works through import npm:matrix-js-sdk, but the README says that route is not officially supported. The README also tells Node.js users to install the latest LTS version, and package.json sets engines node to >=22.0.0.

startClient begins a /sync loop and the first sync state decides whether to continue

Starting the client takes one call with an option for how much history to pull on the first sync:

javascript
await client.startClient({ initialSyncLimit: 10 });

The README then shows a one-time listener on the sync event, which receives the new state, the previous state and the response:

javascript
client.once(ClientEvent.sync, function (state, prevState, res) {
    if (state === "PREPARED") {
        console.log("prepared");
    } else {
        console.log(state);
        process.exit(1);
    }
});

In that example a state other than PREPARED logs the state and exits the process with code 1. That is a choice made by the sample, not by the SDK. The README shows only this exit-on-failure form and lists no other sync states, so check the SDK's API documentation before handling them.

Sending uses sendEvent with a room ID, an event type and a content object

Sending a message calls sendEvent with the room ID, the event type m.room.message, a content object, an empty transaction string and a callback:

javascript
const content = {
    body: "message text",
    msgtype: "m.text",
};
client.sendEvent("roomId", "m.room.message", content, "", (err, res) => {
    console.log(err);
});

Receiving goes through the timeline event, filtered by type:

javascript
client.on(RoomEvent.Timeline, function (event, room, toStartOfTimeline) {
    if (event.getType() !== "m.room.message") {
        return; // only use messages
    }
    console.log(event.event.content.body);
});

The SDK handles local echo, which means a just-sent message appears in the timeline as sending until the remote echo arrives. This avoids a gap between pressing send and seeing the message. Messages that fail are marked as not sent, and requests are retried after network errors and after rate limiting errors.

MemoryStore keeps events in RAM by default, so nothing survives a restart

By default the client uses MemoryStore to hold events as they arrive. The README shows how to walk what is stored:

javascript
Object.keys(client.store.rooms).forEach((roomId) => {
    client.getRoom(roomId).timeline.forEach((t) => {
        console.log(t.event);
    });
});

The consequence follows from the name. A process that restarts starts with an empty store and has to sync again, and a long-running bot that joins many rooms keeps their timelines in memory.

On top of the store the SDK exposes objects such as Rooms, RoomState, RoomMembers and Users, which emit events when names change, messages arrive, membership changes or presence changes. It also tracks room member state over several events, covering typing, power levels and membership, and it generates friendly room and member names. The MatrixClient and many of these objects implement EventEmitter, so you subscribe with on and once.

Servers that enforce MSC3916 reject media downloads without an Authorization header

Servers supporting MSC3916, which arrived in Matrix 1.11, require an Authorization header when a client downloads or thumbnails media. The README marks this as important at the top of the quickstart. For Node.js the fix can be one flag on mxcUrlToHttp, and the README shows the call with useAuthentication set to true and allowRedirects set to true.

Browsers are harder. An image element cannot attach a header, so the README says web apps may need a Service Worker to add the Authorization header when media endpoints are used in elements and similar.

A warning in the README states that in future the SDK will only return authentication-required URLs, so the header population becomes mandatory. The sample for allowDirectLinks says it should generally be left false. If your app builds avatar or file links from mxc URIs, this is the first behaviour to test against a current homeserver.

Backward compatibility is bounded at four spec releases and no spec version is fully implemented

The README names a minimum Matrix server version of v1.1. It also sets a policy: a feature supported by the SDK is guaranteed for at least 4 spec releases. If the specification removes a feature in v1.4, the SDK may remove it once v1.8 is released.

It adds that the SDK has no guarantee of implementing every feature of any particular spec release. The text says this can mean the SDK calls endpoints from before Matrix 1.1. So the minimum version is a floor for compatibility, not a feature checklist.

The version numbers move quickly. v44.0.0 was released on 2026-10-13, v45.0.0-rc.0 on 2026-10-19 and v45.0.0 on 2026-10-27, and package.json reports 45.0.0. Major bumps within two weeks mean you should read CHANGELOG.md, which is in the repository, before taking an upgrade. The last push was on 2026-10-22.

The repository builds with Babel and pnpm and tests with Vitest, with end-to-end encryption documented further down

Contributing means a specific toolchain. package.json pins pnpm 12.14.0 through devEngines with onFail set to download. The build script runs build:compile, which uses Babel on src into lib, and then build:types, which emits declarations with tsc. Linting runs tsc --noEmit, oxlint, oxfmt and a workflow validator, and knip checks for unused code. Tests run with vitest run, and coverage:diff uses diff-cover.

The package is ESM, with main at ./lib/index.js, a separate browser entry at ./lib/browser-index.js and typings at ./lib/index.d.ts. The prepare script runs the build, so an install from a git checkout compiles the code.

More complex examples live in examples/node and examples/voip. The README points to its end-to-end encryption section for enabling encryption, and this review does not cover how it is set up. Development is sponsored by Element, which uses the SDK in element-web and element-desktop. The license is Apache-2.0.

Editorial conclusion

Use matrix-js-sdk if you are building a Matrix client or bot in Node.js 22 or newer, or in a bundled browser app, and you want syncing, timelines and retries handled for you. Skip it if you need a promise that every feature of a given Matrix spec release is implemented, because the README explicitly gives none. Before shipping, test media downloads against your homeserver, since servers that require authenticated media reject plain download URLs.

Frequently asked questions

What is the matrix-js-sdk?

It is the Matrix Client-Server SDK for JavaScript and TypeScript. It runs in a browser or in Node.js and provides an object model around the Client-Server API.

What is the Matrix API in matrix-js-sdk?

matrix-js-sdk wraps the Matrix Client-Server API. It handles /sync, pagination, push actions, room member state and WebRTC calling on top of the HTTP API.

How do I use Matrix in JavaScript with matrix-js-sdk?

Run pnpm add matrix-js-sdk, call sdk.createClient with a baseUrl, then call client.startClient. Messages are sent with sendEvent and received through the RoomEvent.Timeline event.

Official sources

  1. License: Apache-2.0
  2. matrix-org/matrix-js-sdk on GitHub
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/matrix-org-matrix-js-sdk.svg)](https://hysenlabs.com/projects/matrix-org-matrix-js-sdk)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/matrix-org-matrix-js-sdk.svg)](https://hysenlabs.com/projects/matrix-org-matrix-js-sdk)

Was this useful?