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

# API reference

> Current public API for @cloak.dev/sdk

This page tracks the current public exports of `@cloak.dev/sdk`.

## Main client: `CloakSDK`

### Constructor

```typescript theme={null}
new CloakSDK({
  keypairBytes?: Uint8Array;
  wallet?: WalletAdapter;
  network?: "mainnet";
  cloakKeys?: CloakKeyPair;
  storage?: StorageAdapter;
  programId?: PublicKey;
  relayUrl?: string;
  debug?: boolean;
})
```

At least one signer path is required: `keypairBytes` or `wallet`.

### Core methods

```typescript theme={null}
sdk.deposit(connection, amountOrNote, options?) => Promise<DepositResult>
sdk.withdraw(connection, note, recipient, options?) => Promise<TransferResult>
sdk.send(connection, note, recipients, options?) => Promise<TransferResult>
sdk.swap(connection, note, recipient, options) => Promise<SwapResult>
```

Also available:

```typescript theme={null}
sdk.privateTransfer(connection, note, recipients, options?)
sdk.generateNote(amountLamports, useWalletKeys?)
sdk.getMerkleProof(connection, leafIndex)
sdk.getCurrentRoot(connection)
sdk.getTransactionStatus(requestId)
```

Storage/key helpers on the class:

```typescript theme={null}
sdk.loadNotes();
sdk.saveNote(note);
sdk.findNote(commitment);
sdk.importWalletKeys(keysJson);
sdk.exportWalletKeys();
sdk.getConfig();
```

## Note API types

```typescript theme={null}
type DepositResult = {
  note: CloakNote;
  signature: string;
  leafIndex: number;
  root: string;
};

type TransferResult = {
  signature: string;
  outputs: Array<{ recipient: string; amount: number }>;
  nullifier: string;
  root: string;
};
```

## UTXO API

Common UTXO transaction exports:

```typescript theme={null}
transact(params, options)
transfer(inputUtxos, recipientPubkey, amount, options)
partialWithdraw(inputUtxos, recipient, withdrawAmount, options)
fullWithdraw(inputUtxos, recipient, options)
swapUtxo(params, options)
swapWithChange(inputUtxos, swapAmount, outputMint, recipientAta, minOutputAmount, options, recipientWallet?)
```

UTXO primitives:

```typescript theme={null}
generateUtxoKeypair()
createUtxo(amount, keypair, mint?)
createZeroUtxo(mint?)
computeUtxoCommitment(utxo)
computeUtxoNullifier(utxo)
```

Full flow guide: [UTXO Transactions](/sdk/utxo-transactions)

## Relay and proof utilities

```typescript theme={null}
new RelayService(baseUrl)
relay.submitWithdraw(...)
relay.submitSwap(...)
relay.getStatus(requestId)
relay.resumeWithdraw(requestId)

computeProofFromChain(connection, merkleTreePDA, leafIndex)
readMerkleTreeState(connection, merkleTreePDA)
buildMerkleTreeFromRelay(relayUrl)
```

Notes:

* UTXO transact/swap flows submit 256-byte proofs and 264-byte public inputs.
* `RelayService` is the low-level submission client; the high-level `CloakSDK` class wraps it for you.

## Fee constants

```typescript theme={null}
FIXED_FEE_LAMPORTS      // 5_000_000
VARIABLE_FEE_NUMERATOR  // 3
VARIABLE_FEE_DENOMINATOR// 1000
MIN_DEPOSIT_LAMPORTS    // 10_000_000
VARIABLE_FEE_RATE       // 0.003
Q64_64_ONE              // 2^64

calculateFee(amount: number)
calculateFeeBigint(amount: bigint)
calculateSolFeeLamports(gross: bigint)
calculateSolNetAmountLamports(gross: bigint)

tokenPerSolBaseUnitsToQ64(price: bigint)
q64ToTokenPerSolBaseUnits(priceQ64: bigint)
calculateSplFixedFeeTokenAmount(priceQ64: bigint)
calculateSplFeeTokenAmount(grossTokenBaseUnits: bigint, priceQ64: bigint)
calculateSplNetAmountToken(grossTokenBaseUnits: bigint, priceQ64: bigint)

isWithdrawAmountSufficient(amount: bigint)
isSplWithdrawAmountSufficient(grossTokenBaseUnits: bigint, priceQ64: bigint)
getDistributableAmount(amount: number)
```

## Error utilities

```typescript theme={null}
CloakError;
ShieldPoolErrors;
RootNotFoundError;
isRootNotFoundError(error);
parseError(error);
parseTransactionError(error);
```

Detailed usage: [Error Handling](/sdk/error-handling)

## Versioned exports

```typescript theme={null}
VERSION; // "1.0.0"
CLOAK_PROGRAM_ID; // mainnet program constant
```

## Protocol and service docs

* [Protocol Architecture](/protocol/architecture)
* [Shield Pool Program](/protocol/shield-pool)
* [Transaction Flows](/platform/transaction-flows)
* [Code Examples](/sdk/examples)
