Skip to content
Docs

Client: wallets

Import a private key

Import a hex private key by family; EVM covers all EVM chains on the allowlist.

Overview

Imports a single private key as kind: "private_key". For family: "evm" omit chainId—the wallet covers all EVM chains on the allowlist. Other families require chainId. Monero imports the spend key only (view is derived); not multi-chain.

Signature

js
await client.wallets.importPrivateKey(options)

Parameters

ImportPrivateKeyOptions

FieldRequiredDescription
privateKeyYes`"0x"` + 64 hex (32 bytes). Monero: 32-byte spend secret.
familyYes`"evm" | "solana" | "tron" | "utxo" | "monero" | …`
chainIdNo`GrayChainId` — **required** when `family !== "evm"`. Ignored for EVM.
labelNo`string` — UI name.
passwordNo`string` — keystore PIN when storage is encrypted.

Response

Promise<Wallet> — kind: "private_key"

ts
{
  id: string;
  label: string;
  kind: "private_key";
  enabledChains: GrayChainId[]; // EVM → all enabled EVM; else single chain
  // …
}

Usage

js
await client.wallets.importPrivateKey({
  privateKey: "0x…",
  family: "evm",
  password: pin,
});

await client.wallets.importPrivateKey({
  privateKey: "0x…",
  family: "solana",
  chainId: "solana",
  password: pin,
});

await client.wallets.importPrivateKey({
  privateKey: "0x…",
  family: "utxo",
  chainId: "bitcoin",
  password: pin,
});

await client.wallets.importPrivateKey({
  privateKey: "0x…", // spend secret
  family: "monero",
  chainId: "monero",
  password: pin,
});

// Help the user pick a family:
const { candidates } = detectPrivateKey(pk);
const pick = candidates.find((c) => c.family === "monero") ?? candidates[0];
await client.wallets.importPrivateKey({
  privateKey: pk,
  family: pick.family,
  ...(pick.family !== "evm" ? { chainId: pick.chainIds[0] } : {}),
  password: pin,
});

Throws

FieldRequiredDescription
conflictNoDerived address already exists on overlapping chains (any wallet kind). Message includes id, label, chains.
invalid_argumentNoBad key length/format, missing chainId for non-EVM, or unknown family.
unauthorizedNoEncrypted storage — bad or missing PIN.