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

# prepareWalletUpgrade

> Prepares a wallet upgrade (e.g., READY to CHIPI or CHIPI v29 to v33). Returns typed data that must be signed by the wallet owner.

<Warning>Server-only method. Requires API secret key.</Warning>

## Usage

```typescript theme={null}
const upgrade = await sdk.prepareWalletUpgrade(
  { walletAddress: "0x..." },
  bearerToken,
);
```

## Parameters

| Parameter         | Type     | Required | Description                                             |
| ----------------- | -------- | -------- | ------------------------------------------------------- |
| `walletAddress`   | `string` | Yes      | Wallet address to upgrade                               |
| `targetClassHash` | `string` | No       | Target class hash (defaults to latest CHIPI)            |
| `bearerToken`     | `string` | No       | JWT token. Falls back to `apiSecretKey` if not provided |

## Return Value

Returns a `Promise<PrepareWalletUpgradeResponse>`:

| Field               | Type         | Description                      |
| ------------------- | ------------ | -------------------------------- |
| `typedData`         | `TypedData`  | SNIP-12 typed data to sign       |
| `currentClassHash`  | `string`     | Current class hash of the wallet |
| `targetClassHash`   | `string`     | Target class hash for upgrade    |
| `currentWalletType` | `WalletType` | Current wallet type              |
| `targetWalletType`  | `WalletType` | Target wallet type after upgrade |

## Example

```typescript theme={null}
// Prepare upgrade from READY to CHIPI
const upgrade = await sdk.prepareWalletUpgrade(
  { walletAddress: "0x04abc...def" },
  bearerToken,
);

console.log(upgrade.currentWalletType); // "READY"
console.log(upgrade.targetWalletType);  // "CHIPI"

// Sign the typed data (using starknet.js Account)
const signature = await account.signMessage(upgrade.typedData);

// Execute the upgrade
const result = await sdk.executeWalletUpgrade(
  {
    walletAddress: "0x04abc...def",
    typedData: upgrade.typedData,
    signature: [signature.r.toString(), signature.s.toString()],
  },
  bearerToken,
);
```
