Function Signature

importPrivateKey(params: {
  privateKey: string;
  chainName: string;
  thresholdSignatureScheme: ThresholdSignatureScheme;
  password?: string;
  onError?: (error: Error) => void;
  backUpToClientShareService?: boolean;
}): Promise<{
  accountAddress: string;
  publicKeyHex: string;
  rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
  externalServerKeyShares: ServerKeyShare[];
}>

Description

Imports an existing 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 private key to import (64 hex characters with 0x prefix)
  • chainName (string) - The chain name (use ‘EVM’ for Ethereum chains)
  • thresholdSignatureScheme (ThresholdSignatureScheme) - The threshold signature scheme for the wallet

Optional Parameters

  • password (string) - Wallet password for security
  • onError ((error: Error) => void) - Error callback function
  • backUpToClientShareService (boolean) - Whether to back up to client share service (defaults to false)

Returns

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

Example

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

const evmClient = await authenticatedEvmClient();

const wallet = await evmClient.importPrivateKey({
  privateKey: '0xYourPrivateKey' as `0x${string}`,
  chainName: 'EVM',
  thresholdSignatureScheme: ThresholdSignatureScheme.TWO_OF_TWO,
  password: 'your-password',
  backUpToClientShareService: false,
});

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

Error Handling

try {
  const wallet = await evmClient.importPrivateKey({
    privateKey: '0xYourPrivateKey',
    chainName: 'EVM',
    thresholdSignatureScheme: ThresholdSignatureScheme.TWO_OF_TWO,
    password: 'your-password',
    onError: (error) => console.error('Import error:', error),
  });
  console.log('Private key imported successfully');
} catch (error) {
  console.error('Failed to import private key:', error);
}