function ExportSolanaPrivateKey() {
const { exportSolanaAccount } = useExportSolanaAccount();
const { solanaAddress } = useSolanaAddress();
const handleExport = async () => {
if (!solanaAddress) return;
try {
const { privateKey } = await exportSolanaAccount({
solanaAccount: solanaAddress
});
console.log("Private Key:", privateKey);
} catch (error) {
console.error("Failed to export private key:", error);
}
};
return (
<button onClick={handleExport}>Export Private Key</button>
);
}
Hook that provides a wrapped function to export Solana account private keys with authentication checks. This hook uses useEnforceAuthenticated to ensure the user is signed in before attempting to export.