> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portalhq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# backupWallet

> Create a backup of the user's wallet.

## Function Signature

```dart theme={null}
Future<PortalBackupResponse> backupWallet({
  required PortalBackupMethod method,
  String? password,
})
```

## Description

Creates a backup of the user's wallet using the specified backup method. The backup allows the user to recover their wallet on a new device.

## Parameters

| Parameter  | Type                 | Required | Description                                       |
| ---------- | -------------------- | -------- | ------------------------------------------------- |
| `method`   | `PortalBackupMethod` | Yes      | The backup method to use                          |
| `password` | `String`             | No       | Required when using `PortalBackupMethod.password` |

### PortalBackupMethod

| Value         | Description                           |
| ------------- | ------------------------------------- |
| `password`    | Backup using a user-provided password |
| `googleDrive` | Backup to Google Drive                |
| `iCloud`      | Backup to iCloud (iOS only)           |
| `passkey`     | Backup using passkey/WebAuthn         |

## Returns

**`PortalBackupResponse`** - An object containing:

| Property     | Type            | Description                                          |
| ------------ | --------------- | ---------------------------------------------------- |
| `cipherText` | `String?`       | The encrypted backup data (for self-managed backups) |
| `shareIds`   | `List<String>?` | List of share identifiers                            |

## Example

```dart theme={null}
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

// Backup with password
final response = await portal.backupWallet(
  method: PortalBackupMethod.password,
  password: 'user-password',
);

// Backup with Google Drive
await portal.configureGoogleStorage(clientId: 'your-client-id');
final gdriveResponse = await portal.backupWallet(
  method: PortalBackupMethod.googleDrive,
);
```

## Errors

| Code                | Description                                       |
| ------------------- | ------------------------------------------------- |
| `NOT_INITIALIZED`   | Portal was not initialized                        |
| `WALLET_NOT_FOUND`  | No wallet exists to backup                        |
| `BACKUP_FAILED`     | The backup operation failed                       |
| `PASSWORD_REQUIRED` | Password method selected but no password provided |

## Related

* [Back up a wallet guide](../guide/back-up-a-wallet)
* [recoverWallet](./recoverwallet)
* [isWalletBackedUp](./iswalletbackedup)
