Skip to main content

Get Private Balance

Retrieve your private ETH balance from the Privacy Cash pool.
import { getBalance } from 'privacycash-evm'

const result = await getBalance({
  signature: string,
  address: string
})

Parameters

ParameterTypeRequiredDescription
signaturestringYesWallet signature of the Privacy Cash sign-in message
addressstringYesYour EVM wallet address

Returns

{
  balance: string // ETH balance as a decimal string, e.g. "0.123456789"
}

Example

import { ethers } from 'ethers'
import { getBalance, 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 result = await getBalance({ signature, address })

console.log('Private ETH balance:', result.balance, 'ETH')

How Balance Works

getBalance() scans all on-chain NewCommitment events emitted by the Privacy Cash contract and attempts to decrypt each one using your derived encryption key. UTXOs that decrypt successfully and have not been spent are summed to produce your total balance. No private key or encryption key is ever sent off-device — all decryption happens locally.

Supported Tokens

Privacy Cash on Base currently supports ETH only. There is no SPL token equivalent on Base.
TokenNotes
ETHNative — returned as a decimal string