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 @testinprod-io/privacy-boost
# or
yarn add @testinprod-io/privacy-boost
# or
pnpm add @testinprod-io/privacy-boost

Quick Example

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

// 1. Initialize SDK
const sdk = await PrivacyBoost.create({
  indexerUrl: 'https://test-api.privacy-boost.sunnyside.io/indexer',
  wethContract: "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, { 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
});
console.log('Transfer tx:', sendResult.txHash);

// 6. Withdraw to any address
const unshieldResult = await sdk.vault.unshield({
  tokenAddress: '0x...token-address',
  amount: 250000000000000000n, // 0.25 tokens
  recipientAddress: '0x...recipient-address',
});
console.log('Withdraw tx:', unshieldResult.txHash);

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}`);
  },
});

Multi-Chain

Operate on additional blockchains from the same SDK instance:
// Create a chain client (only indexerUrl is required)
const arbitrum = sdk.chain({ indexerUrl: 'https://arb.example.com' });

// Authenticate and use it like the primary SDK
await arbitrum.authenticate(adapter);
await arbitrum.vault.shield({ tokenAddress: '0x...', amount: 1000n });
See the Multi-Chain guide for details.

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