SDK Overview
2.1 Installation
npm install @zkgate/sdk
# or
yarn add @zkgate/sdk
# or
pnpm add @zkgate/sdk2.2 Initialization
The SDK needs to know:
which environment you are using (testnet / mainnet)
your projectId / poolId (assigned during onboarding)
optional relayer endpoint if you don’t want users to pay gas on-chain.
import { ZKGateClient } from "@zkgate/sdk";
const zkClient = new ZKGateClient({
projectId: "my-project-001",
poolId: "pool-DEX-001",
env: "testnet", // "mainnet" when live
relayerUrl: "https://relayer.zkgate.io", // optional
});2.3 Core Concepts in the SDK
commitment – a private representation of a user’s balance / position.
nullifier – prevents double-spend of commitments.
note – user-friendly wrapper around commitments (similar to UTXO).
proof – zero-knowledge proof generated client-side or via prover service.
The SDK abstracts most of these away. In many cases you just call:
deposit()executePrivate()withdraw()
2.4 Common Flows
2.4.1 Private Deposit Flow
User sends assets into the ZK Pool and receives a private note.
await zkClient.deposit({
asset: "USDC",
amount: "1000",
fromAddress: userPublicAddress, // EVM, Solana, etc.
chainId: 8453, // example
});Under the hood, the SDK will:
Call the bridge contract on the origin chain.
Wait for confirmation.
Generate a commitment and send it to the ZKGate API.
Receive a note or local record representing the private balance.
2.4.2 Executing a Private Action (generic)
All private operations (swap, transfer, stake, lend, vote, etc.) go through a unified interface:
await zkClient.executePrivate({
action: "swap",
poolId: "pool-DEX-001",
payload: {
fromAsset: "USDC",
toAsset: "ZK",
amountIn: "500",
minAmountOut: "490",
},
});The SDK will:
Select appropriate notes/commitments.
Build a witness for the circuit.
Generate a ZK proof (in browser or via remote prover).
Submit the proof + encrypted payload to the ZKGate sequencer.
2.4.3 Private Withdraw Flow
User wants to exit the private pool to a public chain address:
await zkClient.withdraw({
asset: "USDC",
amount: "300",
destinationAddress: "0xUserPublicWallet",
chainId: 8453,
});The SDK will:
Build a ZK proof showing:
the user owns enough private balance
the note has not been spent before.
Submit withdraw request to the ZKGate L2.
Once finalized, trigger the bridge contract to send funds to the destination.
2.5 Error Handling & Events
The SDK exposes events / hooks to help you build UX:
zkClient.on("proofGenerated", (info) => {
console.log("Proof generated:", info);
});
zkClient.on("batchSubmitted", (info) => {
console.log("Batch submitted:", info.batchId);
});
zkClient.on("finalized", (info) => {
console.log("Finalized on L1:", info.txHash);
});You can use these events to show loading states, progress indicators, or “finalized” badges in your dApp.
Last updated