Multi-chain wallets
Create a wallet and derive addresses
Create an HD wallet with @gray3/client and read one address per chain from a single account.
Install the SDKs
npm install @gray3/client @gray3/keystore better-sqlite3Create the client
GrayClient.create() sets up the client. Pass a keystore so wallets persist between sessions, and an optional chains allowlist to limit which chains new wallets derive addresses for. This example uses the Node.js SQLite backend, which needs npm install better-sqlite3. For browsers, Expo, React Native, and Chrome extensions, follow the setup for your platform in Platforms.
import { GrayClient } from "@gray3/client";
import { GrayKeystore } from "@gray3/keystore";
const keystore = await GrayKeystore.create({
sqlite: { path: "./wallets.db" },
password: pin, // the user's password or PIN; encryption is on by default
});
const client = await GrayClient.create({
storage: keystore,
chains: ["ethereum", "base", "solana", "bitcoin"],
});Create a wallet
client.wallets.create() generates a new BIP-39 recovery phrase on the device and returns a Wallet. Each wallet starts with one HD account.
const wallet = await client.wallets.create({
label: "Main",
password: pin,
});
// Show this once during onboarding so the user can back it up.
const recoveryPhrase = wallet.exportMnemonic();To restore an existing wallet, use client.wallets.importMnemonic(). To track an address without any secrets, use client.wallets.watch().
Derive addresses
Get an account with wallet.account(index), then read the address for any enabled chain with account.address(chainId). Addresses are derived locally and involve no network call.
const account = wallet.account(0);
account.address("ethereum"); // "0x…" (also valid on base)
account.address("solana"); // base58 address
account.address("bitcoin"); // "bc1…"
// Every enabled chain at once:
for (const { chainId, address, path } of account.addresses()) {
console.log(chainId, address, path);
}Send these public addresses to your backend. They are all your backend needs to load balances and history. Learn more in Derive addresses per chain.