Skip to main content
Use this page when you want the smallest possible end-to-end Cloak integration. This snippet covers:
  • shielded SOL deposit
  • full withdrawal (send)
  • partial withdrawal (keep change private)
For minimal script generation, keep this exact interface:
  • file: send-sol-private.ts
  • command: npx tsx send-sol-private.ts <recipientPubkey> <lamports>
  • env vars: SOLANA_RPC_URL, KEYPAIR_PATH
Guardrails:
  • keep tx amounts as bigint
  • use KEYPAIR_PATH (file-based keypair), not raw private key env vars
  • do not parse SOL decimals with float math (parseFloat, AMOUNT_SOL)
  • read recipient/amount from process.argv (<recipientPubkey> <lamports>), not RECIPIENT_ADDRESS/SEND_LAMPORTS env vars
  • keep programId fixed to CLOAK_PROGRAM_ID internally
  • rely on SDK stale-root retries for standard flows
  • call process.exit(0) on success and process.exit(1) on failure

Mainnet smoke test (keypair bytes)

Use this when you want a first real send with explicit runtime values.
Sanity-check before running:
Run your script entrypoint that wraps the snippet above:

Funding and net amount

For SOL withdraw/send paths:
  • gross = abs(externalAmount)
  • fee = 5_000_000 + floor(gross * 3 / 1000)
  • net = gross - fee
Worked example (gross = 50_000_000, i.e. 0.05 SOL):
  • fee = 5_150_000 lamports (0.00515 SOL)
  • net = 44_850_000 lamports (0.04485 SOL)
Recommended first-run sender balance for this smoke test: 0.07 SOL or higher. Next: Code Examples