Guides

Withdraw a private balance

Move what drops paid you from your private balance to any Solana address.

Every drop you claim pays a private note into your balance on Solana Privacy Rings. Withdrawing moves your notes of one asset to a Solana address you choose. The withdrawal is relayed like a claim, so the wallet you enrolled with doesn't sign it or appear in it.

Read your balance

Open /app/balance and choose Unlock. Your browser derives your payout keys from the same signature you enrolled with, reads the program's payout traffic and opens the notes addressed to you. It shows your balance per asset and, under Incoming, each note that arrived. Only a device your wallet has unlocked can read it; Refresh reads again.

Withdraw in the app

  1. Fill in the form

    Under Withdraw, pick the asset and enter the address under To address. The address can be any Solana address, including a fresh one. The form shows what arrives there after the relay fee, which is taken once per note.

  2. Withdraw

    Choose Withdraw with the asset's name. The page shows each step:

    1. Proved on this device: your browser proves a Rings transaction for each note of the asset, counting them as it goes.
    2. Relayed: the API sends each one through Once's withdraw instruction.
    3. Landed at the address: the funds are at the address.
  3. Sent

    The page shows Sent, and your balance reads again.

A withdrawal spends a payout note whole and pays the relayer a relay fee from it, so the app withdraws every note of the asset and the address receives their sum minus one relay fee per note. A drop's share has already paid one relay fee when it was claimed, so it reaches a public address minus two.

What is public

The destination address and the amount it receives are public, as with any transfer to a public address. Which claims the notes came from is not.

From code

The SDK has every piece: a Rings client, the payout keys from the unlock signature, a scanner that finds the notes those keys open, and the withdrawal proof.

ts
import { address } from '@solana/kit'
import {
  createClient, createOwnerScanner, createRingsClient, encodeWithdrawalRequest,
  holdersFromSignature, proveHolderWithdrawal, RINGS_APP_LABEL,
} from '@once/sdk'

// wallet: the enrolled wallet's address
// unlockSignature: its signature over unlockMessage(), made on this device
// destination: the public address to pay

const api = createClient(process.env.ONCE_API!)
const config = await api.config()
const sol = config.assets.find((a) => a.symbol === 'SOL')!
const usdc = config.assets.find((a) => a.symbol === 'USDC')!

const spr = await createRingsClient({
  cluster: 'localnet',
  solanaRpcUrl: config.rings.rpcUrl,
  indexerUrl: config.rings.indexerUrl,
  proverUrl: config.rings.proverUrl,
})
const holders = await holdersFromSignature(RINGS_APP_LABEL, address(wallet), unlockSignature)
const holdersAuthority = address(config.authorityPdas.holders!)

// Every payout note this wallet's keys open, spent or not
const scanner = createOwnerScanner({ spr, authority: holdersAuthority, holders, kinds: ['claim'] })
const notes = (await scanner.scan()).filter((note) => !note.spent)

// Withdraw each note whole
for (const note of notes) {
  const spend = await proveHolderWithdrawal({
    spr,
    config: { usdcMint: usdc.mint, holdersAuthority, solRelayFee: sol.claimRelayFee, usdcRelayFee: usdc.claimRelayFee },
    relayer: config.relayer!,
    destination,
    note,
  })
  const { jobId } = await api.relayWithdrawal(encodeWithdrawalRequest(spend))
  let job = await api.getJob(jobId)
  while (job.status !== 'confirmed' && job.status !== 'failed') {
    await new Promise((r) => setTimeout(r, 500))
    job = await api.getJob(jobId)
  }
  console.log(spend.asset, spend.netAmount, job.status, job.signature)
}
holders.destroy()

destroy() wipes the payout keys from memory once the withdrawals are sent.

If it stops

Not sent with a message means a withdrawal didn't land. The notes it would have spent are still in your balance; choose Withdraw again.