Skip to main content

Sample Project

https://github.com/Privacy-Cash/privacy-cash-evm-sdk/blob/main/example/

Installation

npm install privacycash-evm --save
Requires Node.js 20+. The SDK is written in TypeScript and includes type definitions.

Signing In

The SDK uses a wallet signature to derive your private encryption key and UTXO keypair. Ask the user to sign a fixed message:
import { ethers } from 'ethers'
import { BASE_NETWORK, ETH_NETWORK } 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()
The resulting signature and address strings are passed directly to each SDK function. Pass the selected network to read from and submit to the correct EVM deployment.

Sending Transactions

deposit() requires a txSender callback that signs and submits the raw transaction:
const txSender = async (unsignedTx: any) => {
  const tx = await signer.sendTransaction(unsignedTx)
  await tx.wait()
  return tx.hash
}

Interacting with Privacy Cash

Once the above steps are done, you can check balance, make deposits and withdrawals.

Supported Networks

Privacy Cash EVM currently supports mainnet deployments only:
NetworkChain IDSDK constantSupported tokens
Base8453BASE_NETWORKETH, USDC
Ethereum1ETH_NETWORKETH, USDT
import {
  BASE_NETWORK,
  ETH_NETWORK,
  deposit,
  withdraw,
  getBalance,
} from 'privacycash-evm'

await getBalance({ signature, address, network: BASE_NETWORK })
await getBalance({ signature, address, network: ETH_NETWORK })
If network is omitted, the SDK reads NEXT_PUBLIC_CHAIN_ID and falls back to Base (8453).

Key Path

All functions accept a keyBasePath parameter pointing to the circuit zkey file (without extension):
keyBasePath: './circuits/transaction'  // loads ./circuits/transaction2.zkey
For Next.js projects, place the .zkey file in the public/ folder:
keyBasePath: '/circuit'  // loads /circuit2.zkey from public/