> ## 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.

# Quickstart

> Install, open the account from a wallet, shield, send privately and withdraw, one call each

This page is the first-run path with [`createCloak`](https://docs.cloak.ag/sdk/create-cloak): open the account from a
wallet, shield some USDC, send part of it privately, and withdraw.

> [!WARNING]
>
> Cloak runs on Solana mainnet only, and there is no test network. Test with small amounts: the
> smallest USDC deposit is 1 USDC, and a withdrawal pays the pool's fee (see
> [What this costs](#what-this-costs)). Use a wallet you can afford to experiment with.

## 1. Install

You need Node 22 or later, or a browser bundler, and a mainnet RPC URL of your own: the default
public endpoint is rate-limited.

```bash theme={null}
npm install @cloak.dev/sdk@^0.2.20
```

## 2. Open the account

Pass the wallet the user connected. Its signature of a fixed message opens the account, the same one
the Cloak mobile app shows for that wallet. The first time a wallet is seen on a device it signs
twice, so the SDK can check it signs the same way each time:

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

// `wallet` is what your wallet library hands you: useWallet(), a Wallet Standard wallet,
// window.ethereum, a Privy wallet. createCloak lists them all.
const cloak = await createCloak({ wallet, rpc: "https://<your-mainnet-rpc>" });
console.log("Cloak address:", cloak.address); // share it to get paid privately
```

## 3. Move money

```ts theme={null}
await cloak.shield({ from: "solana", token: "USDC", amount: "5" }); // the wallet signs the deposit
await cloak.send({ to: "cloak_…", token: "USDC", amount: "1" }); // private: no prompt, no SOL
await cloak.withdraw({ to: "<a Solana address>", token: "USDC", amount: "1" }); // exactly 1 arrives
console.log(await cloak.balance()); // { USDC: "…", USDT: "0", SOL: "0", BRS: "0" }
```

Each call resolves with a receipt (`status`, `amount`, `fee`, `txs`) and throws a `CloakCallError`
whose `code` says what happened and whose `retryable` says whether trying again can work. Sending to
another network is the same call with a different `to`; see [Other networks](https://docs.cloak.ag/guides/cross-chain.md).

## 4. The same calls from a server script

A script signs with a key it holds instead of a connected wallet:

```ts theme={null}
import { readFileSync } from "node:fs";
import { createCloak, isCloakCallError, memoryStorage, signerFromSecretKey } from "@cloak.dev/sdk";

const wallet = await signerFromSecretKey(
  Uint8Array.from(JSON.parse(readFileSync(process.env.KEYPAIR_PATH!, "utf8")) as number[]),
);
const cloak = await createCloak({ wallet, rpc: process.env.SOLANA_RPC_URL, storage: memoryStorage() });
cloak.on("finished", (item) => console.log("finished from an earlier run:", item));

try {
  console.log(await cloak.shield({ from: "solana", token: "USDC", amount: "5" }));
  console.log(await cloak.withdraw({ to: wallet.address, token: "USDC", amount: "1" }));
  console.log("Balance:", await cloak.balance());
} catch (e) {
  // Every error names its code, whether a retry can work, and where the money is.
  console.error(isCloakCallError(e) ? String(e) : e);
  process.exitCode = 1;
}
```

```bash theme={null}
export SOLANA_RPC_URL="https://<your-mainnet-rpc>"
export KEYPAIR_PATH="$HOME/.config/solana/id.json"   # absolute path to a Solana keypair file
npx tsx quickstart.ts
```

The wallet needs the USDC and a little SOL for the deposit transaction. The first proof downloads
the circuit bundle (cached afterwards), so expect the first run to be slower. A long-running service
passes a `storage` that outlives the process; see [Business mode](https://docs.cloak.ag/sdk/create-cloak.md#business-mode).

## What this costs

Fees are charged by the on-chain program, only when value leaves the pool:

* Shields and private sends carry no protocol fee (network fees only).
* A withdrawal pays the pool's fee. `withdraw` adds it on top, so exactly the amount you name
  arrives, and `quote` shows it before anything moves.

See [Fee model](https://docs.cloak.ag/concepts/fees.md) for each pool's figures.

## Where to go next

* [createCloak](https://docs.cloak.ag/sdk/create-cloak.md): every call, receipts, business mode and error codes.
* [Other networks](https://docs.cloak.ag/guides/cross-chain.md): shield from Base, Polygon and Sui; send to Base, Polygon, Sui and
  Tron; BRS to and from Base.
* [Code examples](https://docs.cloak.ag/examples/free-functions.md): partial withdrawals, swaps, payroll, history.
* [Low-level API](https://docs.cloak.ag/sdk/low-level-api.md#end-to-end-script): the same flow with the free functions.
* [Wallet integrations](https://docs.cloak.ag/wallets/overview.md): Phantom, Privy, smart wallets and more.
* [Core concepts](https://docs.cloak.ag/concepts/utxo-model.md): commitments, nullifiers, viewing keys.


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