Skip to main content

withdraw()

withdraw() is a function from privacycash/utils used to withdraw SOL from the PrivacyCash protocol to a specified recipient address.

Parameters

The withdraw() function takes a configuration object with the following properties:
ParameterTypeDescription
amount_in_lamportsnumberThe amount of SOL to withdraw, specified in lamports.
connectionConnectionSolana web3 connection object.
encryptionServiceEncryptionServiceAn instance of the EncryptionService used for decrypting UTXO data.
keyBasePathstringThe base path for loading circuit zkeys (e.g., '/circuit2').
publicKeyPublicKeyThe owner’s Solana public key.
storageStorageA storage object that implements the Web Storage API (e.g., localStorage).
recipientPublicKeyThe Solana address that will receive the withdrawn funds.
lightWasmanyThe Poseidon hasher instance (usually from @lightprotocol/hasher.rs).

Example Usage

import { withdrawSPL } from "privacycash/utils"
import { PublicKey } from "@solana/web3.js"

const result = await withdrawSPL({
    mintAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
    base_units: 1_000_000, // 1 USDC
    connection: connection,
    encryptionService: encryptionService,
    keyBasePath: '/circuit2',
    publicKey: userPublicKey,
    storage: localStorage,
    recipient: new PublicKey('...'),
    lightWasm: hasher,
});

withdrawSPL()

withdrawSPL() is used to withdraw SPL tokens from the PrivacyCash protocol to a specified recipient address.

Parameters

The withdrawSPL() function takes a configuration object with the following properties:
ParameterTypeDescription
mintAddressstringThe mint address of the SPL token.
base_unitsnumberThe amount of tokens to withdraw, specified in base units.
connectionConnectionSolana web3 connection object.
encryptionServiceEncryptionServiceAn instance of the EncryptionService.
keyBasePathstringThe base path for loading circuit zkeys.
publicKeyPublicKeyThe owner’s Solana public key.
storageStorageA storage object (e.g., localStorage).
recipientPublicKeyThe Solana address that will receive the withdrawn funds.
lightWasmanyThe Poseidon hasher instance.

Example Usage

import { withdraw } from "privacycash/utils"
import { PublicKey } from "@solana/web3.js"

const result = await withdraw({
    amount_in_lamports: 1_000_000_000, // 1 SOL
    connection: connection,
    encryptionService: encryptionService,
    keyBasePath: '/circuit2',
    publicKey: userPublicKey,
    storage: localStorage,
    recipient: new PublicKey('...'), // Recipient address
    lightWasm: hasher,
});