Skip to main content

Client Factories

Factories create a fully configured ZkpClient with platform-specific defaults. Use these instead of constructing ZkpClient directly.

createWebClient@zk-privacy/web

import { createWebClient } from '@zk-privacy/web';

const client = createWebClient({ chainId: 8453 });

Returns a ZkpClient synchronously. Solver and prover load on demand (first getBalance() or transfer() call). Call await client.preload() to eagerly initialize.

Under the hood: WASM solver, WASM prover (NoirJS + bb.js), IndexedDB for persistent storage, circuits fetched from public CDN.

createNodeClient@zk-privacy/node

import { createNodeClient } from '@zk-privacy/node';

const client = await createNodeClient({ chainId: 8453 });

Returns a Promise<ZkpClient> (async for thread detection). Solver and prover load on demand.

Under the hood: WASM solver, WASM prover (NoirJS + bb.js), file-based storage, circuits bundled in the package.

Configuration

FieldTypeDefaultDescriptionPlatform
chainIdnumbermust be providedNetwork chain IDboth
rpcUrlstringchain defaultRPC endpoint overrideboth
tokensRecord<string, Address>chain defaultsToken map override (e.g. { USD: '0x...' })both
relayerUrlstringchain defaultGas-sponsored transactionsboth
onProgress(stage, progress?) => voidoptionalLoading progress callbackboth
onLog(level, category, msg, data?) => voidconsole.logSDK log callbackboth
circuitsCdnBaseUrlstringhttps://cdn.zkprivacy.dev/circuits/v1Circuit JSON CDN base URLweb only

Direct construction

For custom backends (native mobile, test mocks), construct ZkpClient directly with ZkpClientConfig — see Advanced: ZkpClient internals.