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

# Phantom and Wallet Standard

> Open a Cloak account and shield from Phantom, Solflare, Backpack or any Wallet Standard wallet

Phantom, Solflare, Backpack and most current Solana wallets register themselves through
[Wallet Standard](https://github.com/wallet-standard/wallet-standard). `createCloak` drives these
wallets through their byte-level `solana:signMessage` and `solana:signTransaction` features, so you
need no `@solana/web3.js` and no wallet adapter.

## Prerequisites

* A browser app with a bundler (Next.js, Vite).
* `@cloak.dev/sdk` 0.2.20 and `@wallet-standard/app`.
* A mainnet RPC URL. See [Network and RPC](https://docs.cloak.ag/resources/network-and-rpc.md).

```bash theme={null}
npm install @cloak.dev/sdk@^0.2.20 @solana/kit @wallet-standard/app
```

## 1. Find the wallet

```ts theme={null}
import { getWallets } from "@wallet-standard/app";

// Every Wallet Standard wallet installed in this browser.
const installed = getWallets().get();
const phantom = installed.find((w) => w.name === "Phantom");
if (!phantom) throw new Error("Phantom is not installed");
```

Show `installed` as a picker in a real app. Each entry has a `name` and an `icon`.

## 2. Open the account

```ts theme={null}
import { createCloak, isCloakCallError } from "@cloak.dev/sdk";

try {
  const cloak = await createCloak({
    wallet: phantom, // the Wallet Standard wallet object
    rpc: process.env.NEXT_PUBLIC_SOLANA_RPC_URL,
  });
  console.log("Cloak address:", cloak.address);
} catch (e) {
  // CloakCallError carries a stable `code`; anything else is the wallet's own error,
  // for example the user closing the signature prompt.
  console.error(isCloakCallError(e) ? `${e.code}: ${e.message}` : e);
}
```

If the wallet is not connected yet, the SDK asks it to connect first. Then the wallet shows the
Cloak account message:

```
Cloak shielded transfer key v1

Signing this message derives your private Cloak receive address on this device. It does not approve a transaction and moves no funds.
```

The first time a wallet opens an account on a device, it signs this message twice, so the SDK can
check that it signs the same way each time. Later sessions sign once. Tell users to expect it.

## 3. Shield, send and withdraw

```ts theme={null}
// The wallet approves one transaction. It needs the USDC and a little SOL for the fee.
const shielded = await cloak.shield({ from: "solana", token: "USDC", amount: "5" });
console.log(shielded.status, shielded.txs.solana); // "shielded", "<signature>"

// No wallet prompt from here on: the account signs these requests itself.
await cloak.send({ to: "cloak_…", token: "USDC", amount: "1" });
await cloak.withdraw({ to: "<a Solana address>", token: "USDC", amount: "1" });
```

Only the shield prompts the wallet. Private sends and withdrawals are signed by a key derived from the
account, need no SOL in the wallet, and do not show the user's wallet as the sender.

## With `@solana/wallet-adapter-react`

If your app already uses the wallet adapter, pass `useWallet()` instead. A Wallet Standard wallet
behind the adapter is still driven through its standard features:

```tsx theme={null}
import { useWallet } from "@solana/wallet-adapter-react";
import { createCloak } from "@cloak.dev/sdk";

export function useOpenCloak() {
  const wallet = useWallet();
  return () => createCloak({ wallet, rpc: process.env.NEXT_PUBLIC_SOLANA_RPC_URL });
}
```

The full adapter setup, including legacy adapters and the low-level API, is in
[Solana wallet adapter](https://docs.cloak.ag/wallets/wallet-adapter.md).

## Transaction format and wallet changes

* **Shields are v0 versioned transactions** with address lookup tables. A wallet that can only sign
  legacy transactions cannot shield.
* **Some wallets add instructions** (compute budget, guard instructions) to what they sign. The SDK
  submits the transaction the wallet returns. A SOL shield is close to Solana's 1,232-byte packet
  limit, so additions can push it over. If users of one wallet hit a size error when shielding,
  the low-level API's `transactionVersion: 1` builds a Transaction V1 with a 4,096-byte limit, for
  wallets whose `solana:signTransaction` feature lists version `1`. See
  [Low-level API](https://docs.cloak.ag/sdk/low-level-api.md).
* **The SDK submits.** It never calls the wallet's sign-and-send feature, so the transaction goes
  through your RPC.

## Errors you will see

| Code | Meaning | What to do |
| - | - | - |
| `wallet.rejected` | The user declined connecting the wallet | Let them retry |
| `wallet.not_connected` | The wallet has no account connected | Ask the user to connect it |
| `account.no_signer` | No wallet passed can sign the account message | Pass a wallet that signs messages, or a `cloakKey` |
| `shield.rejected` | The user declined the shield transaction | Nothing moved |
| `shield.failed` | The shield did not complete; retryable | Retry the call |

The full list is in [Error codes](https://docs.cloak.ag/reference/errors.md).

## Related

* [Your first private transaction](https://docs.cloak.ag/get-started/first-private-transaction.md): a complete React walkthrough.
* [Hardware wallets](https://docs.cloak.ag/wallets/hardware-wallets.md): Ledger behind Phantom or Solflare.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.