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

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Release Funds

> Releases tokens from escrow to a user's wallet after verifying an SMT exclusion proof

Called by a provisioned operator to release escrowed tokens to a user's Mainnet
wallet, contingent on a valid Sparse Merkle Tree exclusion proof for the
withdrawal nonce.

<Info>
  This page documents the Sparse Merkle Tree design at solana-private-channels
  commit `c9e2240`, the source of the program deployed to devnet (see
  [Installation](/developers/docs/tools/private-channels/quickstart/installation)).
  Since commit `46a8e24` (2026-09-09), upstream `main` uses an onchain
  withdrawal bitmap instead, and clients generated from `main` don't include
  the SMT parameters or `ResetSmtRoot`.
</Info>

## Accounts

| Account                          | Writable | Signer | Description                                                        |
| -------------------------------- | -------- | ------ | ------------------------------------------------------------------ |
| `payer`                          | ✓        | ✓      | Fee payer                                                          |
| `operator`                       |          | ✓      | Operator signer                                                    |
| `instance`                       | ✓        |        | Escrow instance PDA (root updated onchain)                        |
| `operator_pda`                   |          |        | Operator PDA proving the signer is provisioned                     |
| `mint`                           |          |        | SPL token mint                                                     |
| `allowed_mint`                   |          |        | AllowedMint PDA - validates the mint is permitted on this instance |
| `user_ata`                       | ✓        |        | Recipient's associated token account (destination)                 |
| `instance_ata`                   | ✓        |        | Escrow's associated token account (source)                         |
| `token_program`                  |          |        | SPL Token Program                                                  |
| `associated_token_program`       |          |        | Associated Token Program                                           |
| `event_authority`                |          |        | Event authority PDA for `EmitEvent` CPI                            |
| `private_channel_escrow_program` |          |        | Escrow Program (self-reference for CPI)                            |

## Parameters

| Parameter             | Type        | Description                                                   |
| --------------------- | ----------- | ------------------------------------------------------------- |
| `amount`              | `u64`       | Amount of tokens to release                                   |
| `user`                | `Pubkey`    | Recipient wallet on Mainnet                                   |
| `new_withdrawal_root` | `[u8; 32]`  | Updated SMT root after including this withdrawal's nonce      |
| `transaction_nonce`   | `u64`       | Unique nonce identifying this withdrawal leaf in the SMT      |
| `sibling_proofs`      | `[u8; 512]` | 16 sibling hashes (32 bytes each) for the SMT exclusion proof |

## Returns

Returns a `TransactionBuilder` that can be used to build and send the
transaction.

## Example

```typescript
import { getReleaseFundsInstruction } from "../private-channel-escrow-program/clients/typescript/src/generated/instructions/releaseFunds";

const releaseIx = getReleaseFundsInstruction({
  payer: operatorPayerSigner,
  operator: operatorSigner,
  instance: instancePda,
  operatorPda: operatorPdaAddress,
  mint: mintAddress,
  allowedMint: allowedMintPda,
  userAta: userAtaAddress,
  instanceAta: instanceAtaAddress,
  tokenProgram: TOKEN_PROGRAM_ID,
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
  eventAuthority: eventAuthorityPda,
  privateChannelEscrowProgram: ESCROW_PROGRAM_ID,
  amount: 1_000_000n,
  user: recipientPublicKey,
  newWithdrawalRoot: Array.from(newSmtRoot), // 32 bytes as number[]
  transactionNonce: withdrawalNonce, // u64
  siblingProofs: Array.from(proofBytes) // 512 bytes (16 × 32-byte hashes) as number[]
});
```

## Important Notes

- Caller must be a provisioned operator: `operator_pda` must exist (created by
  `AddOperator`); invalid PDA throws `InvalidOperatorPda`
- `sibling_proofs` is exactly 512 bytes (16 × 32-byte hashes, matching the SMT
  tree height of 16). The generated client types `siblingProofs` and
  `newWithdrawalRoot` as `number[]`, so convert a `Uint8Array` with
  `Array.from(...)`
- `new_withdrawal_root` is the updated SMT root after including this
  withdrawal's nonce. Compute it offchain before calling
- `transaction_nonce` must be valid for `Instance.current_tree_index`; an
  invalid nonce throws `InvalidTransactionNonceForCurrentTreeIndex`
- The program first runs `verify_smt_exclusion_proof`, proving the nonce does
  NOT yet exist against the current root, then runs a separate
  `verify_smt_inclusion_proof` proving the nonce DOES exist in the
  caller-supplied `new_withdrawal_root`. Either check failing throws
  `InvalidSmtProof`
- Only after both checks pass is `Instance.withdrawal_transactions_root` updated
  atomically; the nonce cannot be reused
- Emits an event via `EmitEvent` CPI
