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

# Export Global Wallet Key

## Overview

The global wallet interface does not provide a way to export the wallet key. If you'd like users to be able to export their global wallet key, you can provide an easy interface for them to log into their wallet and export the key.

<Info>
  You should prompt the user to log in with exactly the same credentials as they use to log in to the global wallet.
</Info>

## Pre-requisites

* Check the 'default wallet version' in the embedded wallet section of [the dashboard](https://app.dynamic.xyz/dashboard/embedded-wallets/dynamic#dynamic-embedded-wallet)
* Ensure you are using the same environment ID as you do for your global wallet implementation.

## Steps

<Tabs>
  <Tab title="V3 Wallets">
    Use [the `exportPrivateKey` method](/react-native/wallets/embedded-wallets/mpc/import-export#exportprivatekey-options)

    1. Get the primary wallet

    ```tsx theme={"system"}
    import { useDynamicContext } from "@dynamic-labs/sdk-react-core";

    const { primaryWallet } = useDynamicContext();
    ```

    2. Guard against no primary wallet or no embedded wallet

    ```tsx theme={"system"}
    const handleExportPrivateKey = async () => {
      if (!primaryWallet?.address) {
        setErrorMessage("Please create a wallet first");
        return;
      }

      if (!primaryWallet.connector.isEmbeddedWallet) {
        setErrorMessage("You do not have a global wallet");
        return;
      }
    };
    ```

    3. Get the connector

    ```tsx theme={"system"}
    import { DynamicWaasEVMConnectors } from '@dynamic-labs/waas-evm';

    const connector = primaryWallet?.connector as DynamicWaasEVMConnector;
    ```

    <Tip>
      For EVM, Solana, and Sui wallets, you can use the `DynamicWaasEVMConnector`, `DynamicWaasSolanaConnector`, and `DynamicWaasSuiConnector` respectively.

      ```tsx theme={"system"}
      import { DynamicWaasEVMConnectors } from '@dynamic-labs/waas-evm';
      import { DynamicWaasSolanaConnectors } from '@dynamic-labs/waas-solana';
      import { DynamicWaasSuiConnectors } from '@dynamic-labs/waas-sui';

      const connector = primaryWallet?.connector as DynamicWaasEVMConnector;
      const connector = primaryWallet?.connector as DynamicWaasSolanaConnector;
      const connector = primaryWallet?.connector as DynamicWaasSuiConnector;
      ```
    </Tip>

    4. Define the display container

    ```tsx theme={"system"}
    const displayContainer = document.createElement('iframe');
    ```

    5. Export the private key

    ```tsx theme={"system"}
      const privateKey = await connector?.exportPrivateKey({
        accountAddress: primaryWallet?.address,
        displayContainer: document.createElement('iframe'), // Replace with your secure container
      });
    };
    ```

    ### Full Example

    ```tsx theme={"system"}
    import { useDynamicContext } from "@dynamic-labs/sdk-react-core";

    const { primaryWallet } = useDynamicContext();

    const handleExportPrivateKey = async () => {
      if (!primaryWallet?.address) {
        setErrorMessage("Please create a wallet first");
        return;
      }

      if (!primaryWallet.connector?.isEmbeddedWallet) {
        setErrorMessage("You do not have a global wallet");
        return;
      }

      const connector = primaryWallet?.connector as DynamicWaasEVMConnector;
      const privateKey = await connector.exportPrivateKey({
        accountAddress: primaryWallet?.address,
        displayContainer: document.createElement('iframe'), // Replace with your secure container
      });
    };
    ```
  </Tab>

  <Tab title="V2 Wallets">
    Use the `useEmbeddedReveal` hook.

    ```tsx theme={"system"}
    import { useEmbeddedReveal } from "@dynamic-labs/sdk-react-core";

    const { initExportProcess } = useEmbeddedReveal();

    <button onClick={() => initExportProcess()}>Export Wallet</button>;
    ```
  </Tab>
</Tabs>
