Skip to main content

withdraw()

withdraw() is a function from privacycash-evm used to withdraw ETH from the Privacy Cash protocol to a specified recipient address on Base.

Parameters

ParameterTypeDescription
withdrawAmountInputnumberTotal amount of ETH to withdraw. Fees are deducted from this value.
recipientstringThe Base address that will receive the withdrawn funds.
keyBasePathstringBase path for the circuit zkey (e.g. '/circuit').
signaturestringWallet signature of the Privacy Cash sign-in message.
addressstringThe withdrawer’s EVM wallet address.

Example Usage

'use client'
import { withdraw } from 'privacycash-evm'
import { useAccount } from 'wagmi'

export function WithdrawButton() {
    const { address } = useAccount()

    const handleWithdraw = async () => {
        if (!address) return

        const signature = localStorage.getItem(`evm_sign_${address}`)
        if (!signature) {
            alert('Please sign in first.')
            return
        }

        const recipient = '0xRECIPIENT_ADDRESS'

        const txHash = await withdraw({
            withdrawAmountInput: 0.05,  // Total including fees
            recipient,
            keyBasePath: '/circuit',
            signature,
            address,
        })

        console.log('Withdraw tx:', txHash)
    }

    return <button onClick={handleWithdraw}>Withdraw 0.05 ETH</button>
}


Fee Estimation

To display the estimated received amount before the user submits:
import { RENT_FEE, FEE_RATE } from 'privacycash-evm'

function estimateReceived(withdrawAmount: number): number {
    const flatFee = RENT_FEE                          // 0.00025 ETH
    const rateFee = (withdrawAmount * FEE_RATE) / 10000 // 0.35%
    return withdrawAmount - flatFee - rateFee
}

console.log(estimateReceived(0.1))  // ~0.09940 ETH

Notes

  • withdrawAmountInput is the total amount deducted from your private balance; the recipient receives less after fees.
  • Always validate that withdrawAmountInput <= privateBalance before calling withdraw().
  • The recipient must be a valid EVM address (0x + 40 hex characters).