Documentation Index
Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
Summary
TheuseWalletBackup hook provides methods to manage wallet backup functionality for Dynamic embedded wallets, allowing users to back up their wallet key shares to Google Drive.
For more information on wallet backup, see the Google Drive backup documentation.
The hook needs to be initialized within a child of DynamicContextProvider.
Functions
initBackupProcess
Initiates the wallet backup flow by opening the Dynamic modal and displaying the backup progress view to the user.
This method uses Dynamic’s UI.
void
Errors:
- Throws
"user_not_logged_in"if the user is not authenticated
ensureGoogleLinked
Ensures that the user has linked their Google account. If not already linked, prompts the user to link their Google account via popup.
This method uses Dynamic’s UI.
Promise<boolean> - true if Google account is linked (or successfully linked), false if linking failed.
Example:
backupWallet
Backs up a single wallet’s key shares to Google Drive.
Parameters:
walletToBackup: Object containing wallet informationaddress: string - The wallet addresschain: ChainEnum - The chain the wallet is associated with
Promise<boolean> - true if backup was successful, false otherwise.
Example:
backupAllWallets
Backs up all wallets (or a specified list of wallets) to Google Drive.
This method is headless.
wallets(optional): Array of wallet objects to back up. If not provided, backs up all wallets that need backup.
Promise<void> - Resolves when all backups complete. Automatically refreshes user data after completion.
Example:
startBackup
Starts the backup process with progress tracking and error handling. This function backs up wallets sequentially and updates the backupState as it progresses.
This method is headless.
onComplete(optional): Callback function to execute when backup completes successfullyfromIndex(optional): Index to start backup from (useful for retrying after failure). Default is 0.
Promise<void> - Resolves when backup completes or fails.
Example:
getWalletsBackupStatus
Returns the backup status for all WaaS wallets.
This method is headless.
WalletWithBackupStatus[] - Array of wallets with their backup status.
Example:
getWalletsToBackup
Returns only the wallets that still need to be backed up (status is ‘pending’).
This method is headless.
WalletToBackup[] - Array of wallets that need backup.
Example:
Properties
areAllWalletsBackedUp
A boolean value indicating whether all WaaS wallets have been backed up to Google Drive.
Type: boolean
Example:
isGoogleLinked
A boolean value indicating whether the user has linked their Google account.
Type: boolean
Example:
backupState
An object containing the current state of the backup operation, including progress and error information.
Type: WalletOperationState
Example:
lastBackupError
The error thrown by the most recent backupWallet or backupToCloudProvider call, or undefined if the last attempt succeeded (or no attempt has been made). Updates as React state — components re-render automatically when it changes.
Inspect it during render to drive a post-flight recovery UI for the (rare) case where pre-flight readiness can’t predict that a Google Drive upload will fail — for example, legacy users whose stored OAuth scopes weren’t recorded. Pair with isInsufficientGoogleDriveScopesError to detect missing-scope failures and recover by re-prompting consent via useGoogleDriveBackupReadiness.
lastBackupError is React state and won’t be updated yet immediately after await backupWallet(...). Read it from render, not from the line right after the await.unknown
Example:
clearBackupError
Clears lastBackupError back to undefined. Call this after handling the error so subsequent renders don’t re-trigger your fallback logic.
Returns: void
Scope helpers and error guards
The same module also exports a few utilities for callers building their own pre-flight or post-flight checks against the Google Drive backup flow.GOOGLE_DRIVE_BACKUP_REQUIRED_SCOPES
The readonly tuple of OAuth scopes that must be granted on the user’s Google account for the backup upload to succeed.
findMissingGoogleDriveBackupScopes
Given the scopes the user has granted, returns the subset of required scopes that are still missing.
Parameters:
grantedScopes:readonly string[]
string[]
hasAllGoogleDriveBackupScopes
Convenience boolean — true if grantedScopes covers every required scope.
Parameters:
grantedScopes:readonly string[]
boolean
isInsufficientGoogleDriveScopesError
Type guard for Google Drive backup failures caused by missing or insufficient OAuth scopes. Recover by re-prompting consent (e.g. via useGoogleDriveBackupReadiness().requestAccess()) and retrying the backup.
Parameters:
err:unknown
err is GoogleDriveBackupAccessError
Usage
Advanced Usage
Monitor backup progress and handle errors:Important Notes
- The user must be authenticated to use backup functionality
- Google account linking is required before backing up wallets
- Backup operations are performed sequentially, one wallet at a time
- The backup modal is part of the Dynamic UI and handles user interactions
- Failed backups can be retried from the point of failure using the
failedIndex