Skip to content
Docs

Client: wallets

Initialize the client

Create a GrayClient with optional keystore, chain allowlist, and duplicate policy.

Overview

GrayClient.create builds the wallet manager, optional storage handle, and a chains manager (Gray3 catalog allowlist + custom EVM networks). Chain ids come from @gray3/core.

Signature

js
await GrayClient.create(options?)

Parameters

options?: GrayCreateOptions

FieldRequiredDescription
storageNo`GrayStorage` — e.g. `GrayKeystore`. Enables auto-persist. Omit for memory-only.
chainsNo`GrayChainId[]` — Gray3 catalog allowlist. If omitted, every Gray3 mainnet is enabled; testnets must be listed explicitly. Frozen into new wallets as `enabledChains`.
customChainsNo`CustomChainDefinition[]` — custom EVM networks (auto-enabled). See Supported chains.
duplicatesNo`"strict"` (default) | `"address"` | `"none"` — import / watch / addAccount conflict policy.

Response

Promise<GrayClient>

ts
{
  wallets: Wallets;           // create / import / list / open / remove / monero
  storage: GrayStorage | null;
  chains: ChainsManager;      // ids, list(), add/remove, addCustom/removeCustom
  detectAddress(address): DetectAddressResult;
  detectPrivateKey(privateKey): DetectPrivateKeyResult;
}

client.chains exposes ids, grayIds, list(), get(id), add / remove (Gray3 catalog), addCustom / removeCustom, has, isEnabled, isCustom.

Usage

js
import { GrayClient } from "@gray3/client";
import { GrayKeystore } from "@gray3/keystore";

const client = await GrayClient.create(); // memory only, every mainnet

const client = await GrayClient.create({
  chains: ["ethereum", "base", "solana"],
  duplicates: "strict",
});

client.chains.add(["polygon", "arbitrum"]);
client.chains.remove("solana");

// Polkadot or Bittensor added after create: initialize sr25519 before deriving
client.chains.add("polkadot");
await ensurePolkadotCrypto(); // import { ensurePolkadotCrypto } from "@gray3/client"

// Node.js; see Platforms for browser, Expo, and React Native backends
const keystore = await GrayKeystore.create({
  sqlite: { path: "./gray-wallets.db" }, // npm install better-sqlite3
  password: pin, // encryption: true by default
});
const client = await GrayClient.create({ storage: keystore });

await client.wallets.create({ label: "Main", password: pin });
await client.wallets.open(id, { password: pin });

Testnets

Testnets are separate chain IDs in the catalog (not a network flag). EVM HD addresses match mainnet siblings; use Cloud prepare with the testnet id, then client sign. Helpers: getEvmChainId, isTestnetChain, getMainnetSibling — see Testnet ids.

Throws

FieldRequiredDescription
invalid_argumentNoMalformed options, custom chain shape, or colliding custom id.
unsupported_capabilityNoNon-EVM custom chain. Custom chains must be EVM-compatible.