Skip to main content

deposit()

deposit() is a function from privacycash-evm used to deposit ETH into the Privacy Cash protocol on Base.

Parameters

ParameterTypeDescription
depositAmountInputnumberAmount of ETH to deposit (e.g. 0.05).
keyBasePathstringBase path for the circuit zkey (e.g. '/circuit').
signaturestringWallet signature of the Privacy Cash sign-in message.
addressstringThe depositor’s EVM wallet address.
txSenderFunctionCallback to sign and submit the raw transaction: (unsignedTx: any) => Promise<string>.

Example Usage

'use client'
import { ethers } from 'ethers'
import { deposit } from 'privacycash-evm'
import { useAccount, useWalletClient } from 'wagmi'

export function DepositButton() {
    const { address, connector } = useAccount()
    const { data: walletClient } = useWalletClient()

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

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

        // Build the txSender callback
        const txSender = async (unsignedTx: any) => {
            if (walletClient) {
                return await walletClient.sendTransaction({
                    to: unsignedTx.to as `0x${string}`,
                    data: unsignedTx.data as `0x${string}`,
                    value: BigInt(unsignedTx.value?.toString() ?? '0'),
                })
            }
            // Fallback via ethers BrowserProvider
            const ethereum = await connector?.getProvider()
            const provider = new ethers.BrowserProvider(ethereum as any)
            const signer = await provider.getSigner(address)
            const tx = await signer.sendTransaction(unsignedTx)
            return tx.hash
        }

        const txHash = await deposit({
            depositAmountInput: 0.01,
            keyBasePath: '/circuit',
            signature,
            address,
            txSender,
        })

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

    return <button onClick={handleDeposit}>Deposit 0.01 ETH</button>
}

Notes

  • The txSender callback receives an unsigned transaction object. Your implementation must sign and submit it, then return the transaction hash as a string.
  • Always check that the user is on Base mainnet (chainId === 8453) before calling deposit().
  • A small additional amount (~0.0001 ETH) is needed to cover the Base network fee on top of the deposit amount. Validate balance >= depositAmountInput + 0.0001 before proceeding.