> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.openfort.io/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

# Export private key

Openfort embedded wallets are non-custodial — the user owns the key. `exportPrivateKey` returns the wallet's raw private key as a string so the user can back it up or import the wallet into an external client (MetaMask, Rabby, etc.). This gives users a clear exit path and reinforces that they, not you, control the funds.

:::note
The wallet must be [`.ready`](https://www.openfort.io/docs/products/embedded-wallet/swift/wallet/state) before exporting.
:::

## Usage

`exportPrivateKey` returns the key as a `String?` (`OFExportPrivateKeyResponse` is a typealias for `String`):

```swift
do {
    let privateKey = try await OFSDK.shared.exportPrivateKey()
    guard let privateKey else {
        print("No key returned")
        return
    }
    // Show it to the user behind an explicit reveal action, or hand it to the
    // Keychain / a QR code for transfer. Do not log or persist it in plaintext.
} catch {
    print("Failed to export private key: \(error.localizedDescription)")
}
```

:::warning
The exported key grants **full, irrevocable control** of the wallet. Treat it as the most sensitive value in your app:

* Never log it, send it to your backend, or write it to disk in plaintext.
* Gate the export behind an explicit user action and ideally a biometric (Face ID / Touch ID) check.
* If you must store it, use the iOS **Keychain** with an appropriate accessibility class — not `UserDefaults`.
* Clear it from memory and any UI as soon as the user is done.
:::

## Returns

```swift
OFExportPrivateKeyResponse? // typealias for String? — the raw private key
```

## Next steps

* [Set up a wallet](https://www.openfort.io/docs/products/embedded-wallet/swift/wallet/recovery) — recovery methods that avoid manual key handling.
* [Recovery methods](https://www.openfort.io/docs/configuration/recovery-methods)
