Skip to content
Docs

Platforms

React with Vite

Set up the wallet SDKs and the SQLite web keystore in a React app built with Vite.

1. Install

Package manager
npm install @gray3/client @gray3/keystore sql.js

No polyfills are needed for derivation and signing in modern browsers, and no Vite plugins are required.

2. Open the keystore

Import the sql.js WebAssembly binary with Vite's ?url suffix, so Vite copies it into the build and gives you its URL.

ts
import wasmUrl from "sql.js/dist/sql-wasm.wasm?url";
import { GrayKeystore } from "@gray3/keystore";
import { GrayClient } from "@gray3/client";

export async function openWallets(pin: string) {
  const storage = await GrayKeystore.create({
    sqlite: { web: { name: "gray-wallets", wasmUrl } }, // stored in IndexedDB
    password: pin,
  });
  return GrayClient.create({ storage });
}

name is the IndexedDB record for this database. Call await storage.close() when the user signs out to lock the keystore and flush pending writes.

3. Wallets and your backend

ts
import { GrayClient } from "@gray3/client";

const client = await GrayClient.create({ storage });

// Create a new wallet (or import an existing phrase)
const wallet = await client.wallets.create({ label: "Main", password: pin });
// const wallet = await client.wallets.importMnemonic({ mnemonic, label: "Restored", password: pin });

// Addresses are derived on the device
const account = wallet.account(0);
const evmAddress = account.address("ethereum");
const solAddress = account.address("solana");

// Sign a message; the result names the signing standard
const { signature, address, standard } = await account.signMessage("Hello from Gray3", "ethereum");
// standard === "eip191"
ts
// Your backend URL — it holds the secret key, the app never does
const API = "https://api.example.com";

const res = await fetch(`${API}/portfolio?chainId=ethereum&address=${evmAddress}`, {
  headers: { authorization: `Bearer ${userSessionToken}` }, // your own user auth
});
const body = await res.json();
if (body.error) throw new Error(`${body.error.code}: ${body.error.message}`);
const portfolio = body.data;

Buffer for Gram signing

The SDK does not need a global Buffer, except for Gram (TON) signing. Add one before the first Gram signature:

ts
// npm install buffer — main.tsx, before the app renders
import { Buffer } from "buffer";
globalThis.Buffer ??= Buffer;

Monero wallet sync

Monero keys and addresses work without setup. For wallet sync in the browser, bundle monero-ts yourself (it needs Node.js polyfills in your bundler configuration), serve its monero.worker.js, and register it:

ts
import { configureMonero } from "@gray3/client";

configureMonero({ moneroTs: await import("monero-ts"), workerUrl: "/monero.worker.js" });

Point the wallet at a daemon URL that needs no extra headers, such as a route on your own backend. Never send gray.monero.syncConnection() to the browser, because its headers contain your secret key.