> ## 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.

# importPrivateKey

> Imports an existing EVM private key into the MPC wallet system

## Function Signature

```typescript theme={"system"}
importPrivateKey(params: {
  privateKey: string;
  chainName: string;
  thresholdSignatureScheme: ThresholdSignatureScheme;
  password?: string;
  onError?: (error: Error) => void;
  backUpToDynamic?: boolean;
}): Promise<{
  walletMetadata: WalletMetadata;
  publicKeyHex: string;
  rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
  externalServerKeyShares: ServerKeyShare[];
  externalKeySharesWithBackupStatus: Array<{
    share: ServerKeyShare;
    backedUpToClientKeyShareService: boolean;
  }>;
}>
```

## 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. Returns a [`walletMetadata`](/node/reference/types/wallet-metadata) object (non-sensitive identity + backup pointers) alongside the sensitive `externalServerKeyShares`. **Persist both** — `walletMetadata` in your cache and `externalServerKeyShares` in a secrets vault.

## 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`) - Password to protect the wallet's key shares. **Required when `backUpToDynamic` is `true`.** You can use the same password for all wallets or a unique password per wallet.
* **`onError`** (`(error: Error) => void`) - Error callback function
* **`backUpToDynamic`** (`boolean`) - Whether to back up the first key share to Dynamic's client share service (defaults to false). **When `true`, a `password` must be provided.**

## Returns

* **`Promise<object>`** - Object containing wallet information:
  * `walletMetadata` ([`WalletMetadata`](/node/reference/types/wallet-metadata)) - Non-sensitive identity + backup-pointer metadata. The wallet's address is at `walletMetadata.accountAddress`. Persist this in your cache.
  * `publicKeyHex` - Public key in hex format
  * `rawPublicKey` - Raw public key object
  * `externalServerKeyShares` ([`ServerKeyShare[]`](/node/reference/types/server-key-share)) - Sensitive plaintext shares for MPC operations. Store these in a secrets vault.
  * `externalKeySharesWithBackupStatus` - Array of key shares with their backup status (see [`createWalletAccount`](/node/reference/evm/create-wallet-account) for details)

## Example

```typescript theme={"system"}
import { authenticatedEvmClient } from './client';
import { ThresholdSignatureScheme } from '@dynamic-labs-wallet/node';

const evmClient = await authenticatedEvmClient();

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

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

// Persist both — metadata to cache, shares to vault.
await redis.set(`wallet:${walletMetadata.accountAddress}`, JSON.stringify(walletMetadata));
await vault.write(`wallet:${walletMetadata.accountAddress}/shares`, externalServerKeyShares);
```

## Error Handling

```typescript theme={"system"}
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);
}
```

## Related Functions

* [`createWalletAccount()`](/node/reference/evm/create-wallet-account) - Create new wallet
* [`exportPrivateKey()`](/node/reference/evm/export-private-key) - Export private key
