SDK Reference
The ShieldFlow TypeScript SDK provides a complete interface for interacting with the protocol. It handles deposits, withdrawals, ZK proof generation, and account management.
Installation
npm install @shieldflow/sdkInitialization
Create a ShieldFlow instance with your chain configuration. The SDK automatically discovers registered pools and configures verifier contracts.
import { ShieldFlow } from '@shieldflow/sdk';
const shieldflow = new ShieldFlow({
chainId: 1,
rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY',
entrypointAddress: '0xCFFf9d27e6A23C94447cEA72DDf6B0C3807F5fE5',
});API Reference
deposit()
Creates a new deposit into the Privacy Pool. Generates a cryptographic commitment, submits the on-chain transaction, and derives a 12-word recovery mnemonic from the deposit secrets.
assetstringAsset identifier (e.g. "ETH", "USDC")amountstringHuman-readable deposit amount (e.g. "1.0")Returns: { commitment, mnemonic, txHash }
const result = await shieldflow.deposit({
asset: 'ETH',
amount: '1.0',
});
console.log(result.commitment); // bytes32 commitment hash
console.log(result.mnemonic); // 12-word recovery phrase
console.log(result.txHash); // transaction hashwithdraw()
Generates a ZK proof and submits a withdrawal through the relayer. The proof demonstrates the caller owns a valid commitment without revealing which deposit is being spent.
mnemonicstring12-word recovery phrase from depositrecipientstringDestination address for withdrawn fundsamountstringAmount to withdraw (e.g. "0.5")Returns: { txHash, nullifier }
const result = await shieldflow.withdraw({
mnemonic: 'word1 word2 ... word12',
recipient: '0xRecipientAddress',
amount: '0.5',
});
console.log(result.txHash); // withdrawal transaction hash
console.log(result.nullifier); // nullifier to prevent double-spendragequit()
Emergency exit that bypasses the relayer and ASP. The original depositor can reclaim their full deposit directly on-chain by proving ownership of the commitment.
mnemonicstring12-word recovery phrase from depositReturns: { txHash }
const result = await shieldflow.ragequit({
mnemonic: 'word1 word2 ... word12',
});
console.log(result.txHash); // ragequit transaction hashloadAccount()
Reconstructs account state from a recovery mnemonic. Scans on-chain events to find all deposits associated with the derived secrets and computes current balances.
mnemonicstring12-word recovery phraseReturns: { deposits, balances }
const account = await shieldflow.loadAccount({
mnemonic: 'word1 word2 ... word12',
});
console.log(account.deposits); // array of deposit records
console.log(account.balances); // per-asset balance summarygetDeposits()
Retrieves all deposits made by a specific account address. Queries on-chain Deposited events and returns structured deposit records.
accountstringEthereum address to query deposits forReturns: Deposit[]
const deposits = await shieldflow.getDeposits({
account: '0xYourAddress',
});
// Returns: Deposit[]
deposits.forEach((d) => {
console.log(d.commitment, d.amount, d.asset, d.timestamp);
});Supported Platforms
Node.js (ESM)
Full SDK support with native crypto. Import as an ES module.
Browser (with Web Workers)
ZK proof generation runs in a dedicated Web Worker to avoid blocking the main thread.
React / Next.js
Compatible with React 18+ and Next.js App Router. Use dynamic imports to avoid SSR issues with WASM dependencies.
Web Worker ZK Proofs
Configuration Options
The following options can be passed to the ShieldFlow constructor:
chainIdnumberYesTarget chain ID (e.g. 1 for mainnet, 11155111 for Sepolia)rpcUrlstringYesJSON-RPC endpoint for the target chainentrypointAddressstringYesAddress of the deployed Entrypoint contractrelayerUrlstringNoURL of the ShieldFlow relayer service for private withdrawalsaspUrlstringNoURL of the ASP (Association Set Provider) for compliance verification