useExportPrivateKey hook initiates a private key export for a given wallet. It returns a URL pointing to the Para portal where the key is displayed securely. Open this URL in a browser — never render the key directly in your app.
Hook for exporting a wallet’s private key via the Para portal
useExportPrivateKey hook initiates a private key export for a given wallet. It returns a URL pointing to the Para portal where the key is displayed securely. Open this URL in a browser — never render the key directly in your app.
import { useExportPrivateKey } from "@getpara/react-native-wallet";
import { useExportPrivateKey, useWallet } from "@getpara/react-native-wallet";
import { Alert, Linking } from "react-native";
function ExportKeyButton() {
const { data: wallet } = useWallet();
const { exportPrivateKeyAsync, isPending } = useExportPrivateKey();
const handleExport = () => {
Alert.alert(
"Export Private Key",
"Your private key grants full access to your wallet. Never share it with anyone.\n\nAre you sure?",
[
{ text: "Cancel", style: "cancel" },
{
text: "Export",
style: "destructive",
onPress: async () => {
if (!wallet?.id) return;
try {
const result = await exportPrivateKeyAsync({ walletId: wallet.id });
if (result?.url) {
await Linking.openURL(result.url);
}
} catch (err) {
console.error(err);
}
},
},
]
);
};
return (
<Button
title={isPending ? "Exporting..." : "Export Private Key"}
onPress={handleExport}
disabled={isPending || !wallet?.id}
/>
);
}