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.
You should prompt the user to log in with exactly the same credentials as they use to log in to the global wallet.
Guard against no primary wallet or no embedded wallet
Copy
Ask AI
const handleExportPrivateKey = async () => { if (!primaryWallet?.address) { setErrorMessage("Please create a wallet first"); return; } if (!primaryWallet.isEmbeddedWallet) { setErrorMessage("You do not have a global wallet"); return; }};
Get the connector
Copy
Ask AI
import { DynamicWaasEVMConnectors } from '@dynamic-labs/waas-evm';const connector = primaryWallet?.connector as DynamicWaasEVMConnector;
For EVM, Solana, and Sui wallets, you can use the DynamicWaasEVMConnector, DynamicWaasSolanaConnector, and DynamicWaasSuiConnector respectively.
Copy
Ask AI
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;