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

# exportPrivateKey

> Exports the private key for a specific wallet address

## Function Signature

```typescript theme={"system"}
exportPrivateKey(params: {
  walletMetadata: WalletMetadata;
  password?: string;
  externalServerKeyShares?: ServerKeyShare[];
}): Promise<{ derivedPrivateKey: string }>
```

## Description

Exports the private key for the wallet identified by the supplied `walletMetadata`. The private key is reconstructed from the distributed key shares using `password` for backup decryption if shares are not provided.

<Warning>
  When you pass `externalServerKeyShares` (the caller-supplied path), `walletMetadata.externalServerKeySharesBackupInfo` must also be present — `exportPrivateKey` throws if shares are supplied but backup metadata is missing. The full `walletMetadata` returned from `createWalletAccount` / `importPrivateKey` already includes it; identity-only metadata from `fetchWalletMetadata` will be rejected.
</Warning>

## Parameters

### Required Parameters

* **`walletMetadata`** ([`WalletMetadata`](/node/reference/types/wallet-metadata)) - Non-sensitive wallet metadata persisted from `createWalletAccount()` / `importPrivateKey()`.

### Optional Parameters

* **`password`** (`string`) - Required if the wallet was created with `backUpToDynamic: true`. Used for backup decryption when `externalServerKeyShares` is not provided.
* **`externalServerKeyShares`** ([`ServerKeyShare[]`](/node/reference/types/server-key-share)) - Caller-supplied plaintext shares.

## Returns

* **`Promise<{ derivedPrivateKey: string }>`** - Object containing the exported private key

## Example

```typescript theme={"system"}
import { authenticatedEvmClient } from './client';

const evmClient = await authenticatedEvmClient();

const walletMetadata = JSON.parse(await redis.get(`wallet:${accountAddress}`));
const externalServerKeyShares = await vault.read(`wallet:${accountAddress}/shares`);

const result = await evmClient.exportPrivateKey({
  walletMetadata,
  externalServerKeyShares,
  password: 'user-password',
});

console.log('Private key exported:', result.derivedPrivateKey);
```

## Error Handling

```typescript theme={"system"}
try {
  const result = await evmClient.exportPrivateKey({
    walletMetadata,
    externalServerKeyShares,
    password: 'user-password',
  });
  console.log('Private key exported successfully:', result.derivedPrivateKey);
} catch (error) {
  console.error('Failed to export private key:', error);
}
```

## Security Considerations

* **Private Key Security**: Never store private keys in plain text
* **Key Share Security**: Keep external server key shares secure
* **Session Management**: Implement proper session management
* **Password Protection**: Use strong passwords for wallet encryption

## Related Functions

* [`importPrivateKey()`](/node/reference/evm/import-private-key) - Import existing private key
* [`getEvmWallets()`](/node/reference/evm/get-evm-wallets) - Get all EVM wallets
