Skip to main content

Withdraw ETH

Withdraw ETH from your private balance to any recipient address on Base.
import { withdraw } from 'privacycash-evm'

const txHash = await withdraw({
  withdrawAmountInput: number,
  recipient: string,
  keyBasePath: string,
  signature: string,
  address: string
})

Parameters

ParameterTypeRequiredDescription
withdrawAmountInputnumberYesTotal amount in ETH to withdraw (fees are deducted from this)
recipientstringYesEVM address to receive the funds
keyBasePathstringYesBase path to the circuit zkey file (without extension)
signaturestringYesWallet signature of the Privacy Cash sign-in message
addressstringYesThe withdrawer’s EVM wallet address

Returns

The transaction hash (string).

Example

import { ethers } from 'ethers'
import { withdraw, SIGN_PRIVACY_MESSAGE } from 'privacycash-evm'

const provider = new ethers.providers.JsonRpcProvider(process.env.BASE_RPC_URL!, {
  name: 'base',
  chainId: 8453,
})
const signer = new ethers.Wallet(process.env.PRIVATE_KEY!, provider)

const signature = await signer.signMessage(SIGN_PRIVACY_MESSAGE)
const address = await signer.getAddress()

const txHash = await withdraw({
  withdrawAmountInput: 0.05,         // Total amount including fees
  recipient: '0xRECIPIENT_ADDRESS',  // Any Base address
  keyBasePath: './circuits/transaction',
  signature,
  address,
})

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

Withdrawal Fees

Fees are deducted from the withdrawAmountInput, so the recipient receives less than the requested amount.
ComponentAmount
Flat fee0.00025 ETH per withdrawal
Protocol fee0.35% of withdrawal amount

Fee Calculation Example

const withdrawAmount = 0.1 // ETH

// Flat fee: 0.00025 ETH
// Protocol fee: 0.1 × 0.35% = 0.00035 ETH
// Total fee: ~0.00060 ETH
// Recipient receives: ~0.09940 ETH

How Withdrawals Work

1

UTXO Selection

The SDK scans on-chain events to find your unspent UTXOs (up to 2) to cover the withdrawal amount.
2

ZK Proof Generation

A zero-knowledge proof is generated proving you own the funds and authorizing the exact recipient and amount.
3

On-Chain Submission

The transaction is submitted directly to the Base smart contract. No relayer is needed for Base withdrawals.
4

Funds Received

The recipient receives ETH with no on-chain link to your depositing wallet.

Privacy Guarantee

The withdrawal transaction on-chain contains no information about the original depositor. The zero-knowledge proof ensures:
  • The recipient address cannot be modified
  • The amount cannot be modified
  • Any tampering causes the transaction to revert

Insufficient Balance

If your private balance is less than withdrawAmountInput, the SDK throws:
Insufficient balance. Have X ETH, need Y ETH.
Check your balance first with getBalance().