Skip to main content

Get Private Balance

Retrieve your private ETH or ERC-20 balance from a Privacy Cash EVM pool.
import { getBalance } from 'privacycash-evm'

const result = await getBalance({
  signature: string,
  address: string,
  token?: 'eth' | 'usdc' | 'usdt',
  network?: NetworkConfig | number
})

Parameters

ParameterTypeRequiredDescription
signaturestringYesWallet signature of the Privacy Cash sign-in message
addressstringYesYour EVM wallet address
token'eth' | 'usdc' | 'usdt'NoToken balance to scan. Defaults to 'eth'
networkNetworkConfig | numberNoEVM network. Defaults from NEXT_PUBLIC_CHAIN_ID, then Base

Returns

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

Example

import { ethers } from 'ethers'
import { BASE_NETWORK, ETH_NETWORK, getBalance } from 'privacycash-evm'

const network = ETH_NETWORK // or BASE_NETWORK
const SIGN_MESSAGE = 'Privacy Money account sign in'

const provider = new ethers.providers.JsonRpcProvider(network.rpcUrl, {
  name: network.chainKey,
  chainId: network.chainId,
})
const signer = new ethers.Wallet(process.env.PRIVATE_KEY!, provider)

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

const result = await getBalance({ signature, address, token: 'eth', network })

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 EVM currently supports these token pools:
NetworkTokens
BaseETH, USDC
EthereumETH, USDT