Skip to main content

TypeScript Quickstart

Build a private payment flow in your web app with the TypeScript SDK.
This quickstart gets you running in 5 minutes with minimal explanation. For detailed walkthroughs of each step, see the TypeScript Getting Started guide. For background on configuration and auth options, see Setup.

Installation

npm install @sunnyside-io/privacy-boost
# or
yarn add @sunnyside-io/privacy-boost
# or
pnpm add @sunnyside-io/privacy-boost

Quick Example

import { PrivacyBoost } from '@sunnyside-io/privacy-boost';
import { createWalletAdapter } from '@sunnyside-io/privacy-boost-react';

// 1. Initialize SDK
const sdk = await PrivacyBoost.create({
  serverUrl: 'https://test-api.privacyboost.io',
  wethContractAddress: "0x4200000000000000000000000000000000000006",
  appId: 'app_abc123xyz',
});

// 2. Authenticate (keySource is optional; defaults to walletDerived when no persistence)
const adapter = createWalletAdapter();
const authResult = await sdk.auth.authenticate(adapter);
// Or with a specific key source:
// const authResult = await sdk.auth.authenticate(adapter, { keySource: { type: 'mnemonic', phrase: '...' } });

if (authResult.status === 'authenticated') {
  console.log('Your privacy address:', authResult.privacyAddress);
}
When does credentialRequired fire? credentialRequired only fires when persistence with pin or password unlock is configured. For the simple case (no persistence), authenticate() always returns authenticated directly.
// 3. Check balance
const balance = await sdk.vault.getBalance('0x...token-address');
console.log('Shielded balance:', balance);

// 4. Deposit tokens
const shieldResult = await sdk.vault.shield({
  tokenAddress: '0x...token-address',
  amount: 1000000000000000000n, // 1 token (18 decimals)
});
console.log('Deposit tx:', shieldResult.txHash);

// 5. Send privately
const sendResult = await sdk.vault.send({
  to: '0x04...recipient-privacy-address',
  tokenAddress: '0x...token-address',
  amount: 500000000000000000n, // 0.5 tokens
});
// send() and unshield() return a local placeholder txHash; track the
// real on-chain settlement by requestId instead.
const transfer = await sdk.transactions.getTransferStatus(sendResult.requestId);
console.log('Transfer status:', transfer.status);

// 6. Withdraw to any address
const unshieldResult = await sdk.vault.unshield({
  tokenAddress: '0x...token-address',
  amount: 250000000000000000n, // 0.25 tokens
  recipientAddress: '0x...recipient-address',
});
const withdrawal = await sdk.transactions.getUnshieldStatus(unshieldResult.requestId);
console.log('Withdraw status:', withdrawal.status);
For send() and unshield(), the returned txHash is a client-side placeholder until the canonical on-chain hash is available — poll by requestId (sdk.transactions.getTransferStatus / getUnshieldStatus). For shield(), txHash is the real on-chain hash because the wallet signs and submits it directly.

Progress Tracking

Track operation progress with callbacks:
await sdk.vault.shield({
  tokenAddress: '0x...',
  amount: 1000000000000000000n,
  onProgress: ({ step, message, txHash }) => {
    console.log(`Step: ${step}, Message: ${message}`);
    if (txHash) console.log(`Tx: ${txHash}`);
  },
});

Next Steps

TypeScript Getting Started

Detailed walkthrough of each integration step

Setup Guide

App ID, configuration, and auth method selection

Deposits Guide

Deposits, withdrawals, transfers, and balance queries

API Reference

Complete method signatures and type definitions