Skip to content
Docs

Client: Monero

Sync and restore height

View-key sync with required restore height or date; cache for reads, live sync for send.

Overview

View-key sync scans the chain into a device-local cache (balance + activity + height). After reopen you can read cache without re-syncing; send still needs a live sync in the session (UTXOs are not cached).

Signature

js
await account.monero.sync({
  connection,
  restoreHeight?,   // XOR restoreDate — one required (no silent scan-from-0)
  restoreDate?,
})
  .onProgress((p) => { … })
  .onError((err) => { … })

Parameters

FieldRequiredDescription
connectionYes`{ uri, headers? }` — on Node.js, pass `gray.monero.syncConnection()`. In a browser, `{ uri }` from `gray.monero.browserConnection()` (fetched from your backend). Advanced: a self-hosted monerod `uri`.
restoreHeightNo`number` — required unless `restoreDate` is set. Resumes if checkpoint is higher.
restoreDateNo`Date | string` — alternative to height (e.g. `"2024-06-01"`).

Response

Sync handle resolves with balance (and related fields). Progress events:

ts
type MoneroSyncProgress = {
  height: number;
  percent: number; // session-relative
  // …
};

// After sync / from cache:
account.monero.syncedAt  // ISO of last persisted sync | undefined
await account.monero.balance()
await account.monero.activity(limit?)

Usage

js
import { Gray } from "@gray3/cloud";

const gray = new Gray({ projectId, secretKey });
const a = (await client.wallets.open(id, { password: pin })).account(0);

const { balance } = await a.monero.sync({
  connection: gray.monero.syncConnection(),
  // restoreHeight: 3_200_000,
  // restoreDate: "2024-06-01",
})
  .onProgress((p) => console.log(p.height, p.percent))
  .onError((err) => console.error(err));

await a.monero.balance();
await a.monero.activity();
await a.monero.close(); // drop WASM

// After reopen — reads from cache; prepareTransfer needs sync again
const a2 = (await client.wallets.open(id, { password: pin })).account(0);
await a2.monero.balance();
await a2.monero.activity();

Native birthday hint

js
const mw = await client.wallets.monero.restore({ mnemonic, password: pin });
const a = mw.account(0);
await a.monero.sync({
  connection: gray.monero.syncConnection(),
  ...(mw.monero.birthdayUnix
    ? { restoreDate: new Date(mw.monero.birthdayUnix * 1000) }
    : { restoreHeight: 2_800_000 }),
});

Throws

FieldRequiredDescription
invalid_argumentNoMissing both restoreHeight and restoreDate; bad connection.
unsupported_capabilityNoMonero not enabled on wallet / client.
provider_unavailable / internalNoDaemon / WASM failures during scan (message varies).