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

# exportKey

> Exports a key for a specific chain using external server key shares

## Function Signature

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

## Description

Exports a key for the wallet identified by `walletMetadata`. This is the base-class operation that `exportPrivateKey()` builds on; most callers should use [`exportPrivateKey()`](/node/reference/evm/export-private-key) directly.

<Warning>
  When you pass `externalServerKeyShares` (the caller-supplied path), `walletMetadata.externalServerKeySharesBackupInfo` must also be present — `exportKey` 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

* **`accountAddress`** (`string`) - The wallet address (must include `0x` prefix). Must match `walletMetadata.accountAddress`.
* **`chainName`** (`string`) - The chain name (e.g., `'EVM'`)
* **`walletMetadata`** ([`WalletMetadata`](/node/reference/types/wallet-metadata)) - The cached metadata for this wallet

### Optional Parameters

* **`externalServerKeyShares`** ([`ServerKeyShare[]`](/node/reference/types/server-key-share)) - Caller-supplied plaintext shares. If omitted, the SDK recovers from backup using `password`.
* **`password`** (`string`) - Required if the wallet was created with `backUpToDynamic: true`.

## Returns

* **`Promise<{ derivedPrivateKey: string }>`** - The derived private key as a hex string

## 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 { derivedPrivateKey } = await evmClient.exportKey({
  accountAddress,
  chainName: 'EVM',
  walletMetadata,
  externalServerKeyShares,
  password: 'user-password',
});

console.log('Key exported:', derivedPrivateKey);
```

## Error Handling

```typescript theme={"system"}
try {
  const { derivedPrivateKey } = await evmClient.exportKey({
    accountAddress,
    chainName: 'EVM',
    walletMetadata,
    externalServerKeyShares,
    password: 'user-password',
  });
  console.log('Key exported successfully');
} catch (error) {
  console.error('Failed to export key:', error);
}
```

## Related Functions

* [`exportPrivateKey()`](/node/reference/evm/export-private-key) - Export private key
* [`offlineExportKey()`](/node/reference/evm/offline-export-key) - Export key offline
