Overview
TheExportWallet component provides a secure interface for exporting private keys from embedded wallets. It supports both EVM (externally owned accounts) and Solana accounts, while properly handling edge cases like EVM smart accounts which cannot have their private keys exported.
The core features include:
- Support for EVM (EOA) and Solana account types
- Secure private key copying via isolated iframe
- Address display with copy functionality
- Smart account detection with appropriate warnings
- Composable UI that gives developers full control over layout and styling
- Lifecycle callbacks for monitoring iframe state and copy operations
Architecture
The component is built using a composition pattern that allows for maximum flexibility while providing sensible defaults when customization is not needed.Composition model
TheExportWallet component is composed of several subcomponents that work together to create the complete key export experience. This approach allows developers to customize the UI structure while maintaining the underlying security and functionality.
The main components are:
ExportWallet: The root wrapper component that provides theExportWalletContextand manages stateExportWalletTitle: Renders the title for the export interfaceExportWalletWarning: Displays appropriate warning messages based on account typeExportWalletCopyAddress: Shows the wallet address with copy functionalityExportWalletCopyKeyButton: Renders the secure button for copying the private keyExportWalletFooter: The “Secured by Coinbase” footer
ExportWallet
TheExportWallet component accepts a required address prop and automatically detects the account type (EVM EOA, EVM smart, or Solana) by checking the current user’s accounts. It also provides callback props for monitoring the key export process.
Basic usage:
ExportWalletTitle
TheExportWalletTitle component displays a title for the export interface. By default, it shows “Export your wallet” but can be customized by providing children. It accepts an as prop to render as different HTML elements (default is h2).
ExportWalletWarning
TheExportWalletWarning component automatically displays the appropriate warning message based on the account type:
- For EVM EOA and Solana accounts: “Do not share your private key with anyone”
- For EVM smart accounts: “Cannot export a smart account’s private key; only the owner’s private key can be exported.”
ExportWalletCopyAddress
TheExportWalletCopyAddress component displays the wallet address with a copy button. It uses the address from context and accepts a label prop (defaults to “Your wallet address”).
ExportWalletCopyKeyButton
TheExportWalletCopyKeyButton component renders a secure button that uses an isolated iframe to handle private key operations. The button is rendered differently based on the account type:
- For EVM EOA accounts: Uses
CopyEvmKeyButton - For Solana accounts: Uses
CopySolanaKeyButton - For EVM smart accounts: Returns
null(no button is rendered)
ExportWalletFooter
TheExportWalletFooter component displays the standard Coinbase footer. Its visibility is controlled by the showCoinbaseFooter setting in the app config.
Example: Basic usage with EVM address
Export an EVM account’s private key:Example: Basic usage with Solana address
Export a Solana account’s private key:Example: Export with callbacks
Monitor the export process with lifecycle callbacks:Example: Custom layout
Customize the layout and styling:API Reference
Required Props
address: The wallet address to export. The component automatically detects whether this is an EVM EOA, EVM smart account, or Solana account.
Optional Props
onIframeReady: Callback function invoked when the secure iframe is readyonCopySuccess: Callback function invoked when the private key is successfully copiedonIframeError: Callback function invoked when an error occurs in the secure iframechildren: React nodes for custom layout (if not provided, uses default layout)className: Additional CSS classes to apply to the root element
Security Considerations
- Isolated iframe: Private key operations are handled in an isolated iframe to prevent exposure to the main application context
- Smart account protection: The component automatically detects EVM smart accounts and prevents private key export, displaying an appropriate warning instead
- No key exposure: Private keys are never exposed to JavaScript; they are only copied to the clipboard through the secure iframe
- User warning: Clear warnings are displayed to remind users not to share their private keys
Notes
- EVM smart accounts: Smart accounts use account abstraction and do not have a private key that can be exported. The component will show a warning and hide the copy key button for these accounts. Only the EOA owner’s private key can be exported.
- Security best practices: Always educate users about the importance of keeping their private keys secure and never sharing them