Function Signature

importPrivateKey(params: {
  privateKey: string;
  chainName: string;
  thresholdSignatureScheme: ThresholdSignatureScheme;
  password: string;
}): Promise<{
  accountAddress: string;
  rawPublicKey: string;
  externalServerKeyShares: any[];
}>

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.

Parameters

Required Parameters

  • privateKey (string) - The Solana private key to import
  • chainName (string) - The chain name (use ‘SVM’ for Solana chains)
  • thresholdSignatureScheme (ThresholdSignatureScheme) - The threshold signature scheme for the wallet
  • password (string) - Wallet password for security

Optional Parameters

Returns

  • Promise<object> - Object containing wallet information:
    • accountAddress - The wallet’s account address
    • rawPublicKey - Raw public key
    • externalServerKeyShares - Array of external server key shares

Example

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

const svmClient = await authenticatedSvmClient();

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

console.log('Solana wallet imported:', wallet.accountAddress);

Error Handling

try {
  const wallet = await svmClient.importPrivateKey({
    privateKey: 'YourSolanaPrivateKey',
    chainName: 'SVM',
    thresholdSignatureScheme: ThresholdSignatureScheme.TWO_OF_TWO,
    password: 'your-password',
  });
  console.log('Private key imported successfully');
} catch (error) {
  console.error('Failed to import private key:', error);
}