Function Signature

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

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
  • 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
    • publicKeyHex - Public key in hex format
    • 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',
});

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',
  });
  console.log('Private key imported successfully');
} catch (error) {
  console.error('Failed to import private key:', error);
}