Skip to content

Quickstart

Terminal window
npm install @calimero-network/mero-js

The package ships ESM, CommonJS and a browser build with its own TypeScript declarations. Its one dependency, @phala/dcap-qvl, verifies TDX quotes and is loaded only when the client first meets a real one.

A client talks to one node of a cluster at a time, and fails over to the next when that node stays unavailable. Its policy says which nodes it trusts; nothing is sent to a node until its attestation passes.

import { CalimeroClient, browserPasskey } from '@calimero-network/mero-js';
// A Calimero Cloud cluster by name; its nodes come from the node directory.
const client = await CalimeroClient.connect({
cluster: 'eu-shared-1',
// Trust a node that runs a signed mero-tee release, this one or newer.
policy: { release: { minReleaseVersion: '2.3.109' } },
});

The directory only chooses which nodes to try: each one is still attested under your policy, so a wrong list can only make connecting fail. For a fixed list of nodes, or a cluster you run yourself, give them directly: new CalimeroClient({ baseUrl, nodes, policy }).

Connect to the cluster that serves the page

Section titled “Connect to the cluster that serves the page”

One frontend build often runs in several places: bundled in the app’s .mpk and served by staging, by the shared eu-shared-1 and by a customer’s dedicated cluster, and also on Vercel for CI previews. connectHere finds the cluster without naming it:

import { CLOUD_ENVIRONMENTS, CalimeroClient, cloudEnvironment } from '@calimero-network/mero-js';
// Staging runs debug node images too. Decided by the page's hostname, never by what a server says.
const cloud = CLOUD_ENVIRONMENTS[cloudEnvironment() ?? 'production'];
const client = await CalimeroClient.connectHere({
policy: { release: { minReleaseVersion: '2.3.109', ...cloud.trust } },
// Only where no cluster serves the page (Vercel, localhost): values fixed at build time.
fallback: { cluster: 'staging-1', environment: 'staging' },
});
client.cluster; // e.g. 'eu-shared-1': the cluster that served the page
client.deployment; // the deployment the page was opened for, or null
  • A page a cluster serves reads its own /.well-known/calimero.json and connects to the nodes listed there. Shared, dedicated and staging clusters all work with the same build.
  • Anywhere else it uses fallback: { cluster, environment? } through that Calimero Cloud’s directory, or { baseUrl, nodes? }. A page under a Calimero Cloud apps domain never falls back.
  • The manifest only says where the nodes are; each is still attested under your policy. cloudEnvironment() reads the page’s hostname, which the browser checked over TLS: 'production', 'staging', or null elsewhere.
  • On a Calimero Cloud’s apps domain the client also defaults to that Cloud’s servers: its directory (for a { cluster } with no environment) and its release and collateral mirrors (CLOUD_ENVIRONMENTS[env].cloudUrl). Explicit options win.
  • CLOUD_ENVIRONMENTS[env].trust is what that Cloud’s nodes need in policy.release: nothing for production (locked-read-only only); for staging, profiles (all three image profiles) with allowDebugProfile. With profiles, the node’s own profile is used when it is listed, and its quote must still be that profile’s signed image.
  • A page on Vercel must be a registered origin of your package (client.packages.originsAdd), at a stable address such as a branch alias: each preview deploy gets a new URL.

For a local development cluster (meroctl local up, or merod run --dev), whose nodes send mock quotes, allow them explicitly:

const dev = new CalimeroClient({ baseUrl: 'http://127.0.0.1:2501', policy: { allowMock: true } });

A person’s account is their passkey. signUp creates both and signs in; signIn uses an existing passkey on any node of the cluster.

const session = await client.signUp(browserPasskey(), 'alice');
// later, or on another device that holds the passkey:
await client.signIn(browserPasskey());

The node’s --rp-id and --origins decide which pages may run a passkey ceremony: localhost and http://localhost:3000 by default.

An app instance runs a signed package release, on its own replicated log.

await client.packages.install({ package: 'com.calimero.kv-store', version: '1.0.0' }); // from the cluster's registry
const app = await (await client.apps.create({ name: 'notes', package: 'com.calimero.kv-store', version: '1.0.0' })).appId;
await client.apps.call({ app, method: 'set', args: { key: 'a', value: '1' } });
const { result } = await client.apps.view({ app, method: 'get', args: { key: 'a' } }); // '1'
for await (const event of client.events(app)) {
console.log(event.kind, event.data);
}

call carries an idempotency key, so the client can send it again while the node is unavailable without running it twice. See Apps and packages.