Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt

Use this file to discover all available pages before exploring further.

Function Signature

importPrivateKey(params: {
  privateKey: string;
  chainName: string;
  thresholdSignatureScheme: ThresholdSignatureScheme;
  password?: string;
  onError?: (error: Error) => void;
  backUpToDynamic?: boolean;
}): Promise<{
  walletMetadata: WalletMetadata;
  rawPublicKey: string;
  externalServerKeyShares: ServerKeyShare[];
  externalKeySharesWithBackupStatus: Array<{
    share: ServerKeyShare;
    backedUpToClientKeyShareService: boolean;
  }>;
}>

Description

Imports an existing Solana private key into the MPC wallet system. The private key is split into shares according to the specified threshold signature scheme. Returns a walletMetadata object (non-sensitive identity + backup pointers) alongside the sensitive externalServerKeyShares. Persist bothwalletMetadata in your cache and externalServerKeyShares in a secrets vault.

Parameters

Required Parameters

  • privateKey (string) - The private key to import
  • chainName (string) - The chain name (use 'SVM' for Solana)
  • thresholdSignatureScheme (ThresholdSignatureScheme) - The threshold signature scheme

Optional Parameters

  • password (string) - Required when backUpToDynamic is true.
  • onError ((error: Error) => void) - Error callback function
  • backUpToDynamic (boolean) - Whether to back up the first key share to Dynamic. When true, a password must be provided.

Returns

  • Promise<object> - Object containing wallet information:
    • walletMetadata (WalletMetadata) - Persist in cache.
    • rawPublicKey - Raw public key
    • externalServerKeyShares (ServerKeyShare[]) - Store in secrets vault.
    • externalKeySharesWithBackupStatus - Array of key shares with their backup status

Example

import { authenticatedSvmClient } from './client';
import { ThresholdSignatureScheme } from '@dynamic-labs-wallet/node';

const svmClient = await authenticatedSvmClient();

const { walletMetadata, externalServerKeyShares } = await svmClient.importPrivateKey({
  privateKey: 'YourSolanaPrivateKey',
  chainName: 'SVM',
  thresholdSignatureScheme: ThresholdSignatureScheme.TWO_OF_TWO,
  password: 'your-password',
  backUpToDynamic: true,
});

console.log('Wallet imported:', walletMetadata.accountAddress);

await redis.set(`wallet:${walletMetadata.accountAddress}`, JSON.stringify(walletMetadata));
await vault.write(`wallet:${walletMetadata.accountAddress}/shares`, externalServerKeyShares);