Preview. Requires
@avnu/avnu-sdk >= 4.2.0-next.2 and a proving backend: the Starknet privacy SDK or a STRK20-capable wallet (starknet.js >= 10.4). The sell token must already be in your private balance — deposit into the pool first. Questions? Reach out on Telegram.Setup
The snippets below assume a few objects are already wired up:| Identifier | Source |
|---|---|
getQuotes, executePrivateSwap, buildPrivateSwapFee, submitPrivateSwap, PRIVACY_POOL_ADDRESS | @avnu/avnu-sdk |
account | your Starknet account (e.g. starknet.js Account) |
transfers, Open, provingBlockId | the Starknet privacy SDK |
starknet.paymaster.avnu.fi by default (override with AvnuOptions.paymasterBaseUrl, e.g. sepolia.paymaster.avnu.fi for testing).
How it works
A private swap is anapply_action transaction relayed by avnu’s paymaster. No user signature is needed, since everything settles on-chain straight from the proof. executePrivateSwap orchestrates the four steps:
- Pool fee. The paymaster returns the pool fee to withdraw (token, recipient, amount).
- Private calls.
quoteToCalls({ private: true }): the backend setstakerAddress = executorand returns the inner swapcallsplus theexecutorAddress. - Proof. Your injected
PrivateSwapProverbuilds and proves the private transaction: withdraw the sell amount to the executor, withdraw the pool fee, open a note for the bought token, and invoke the executor with the serialized swap calls. - Submit. The paymaster relays the proof on-chain. The relayer pays gas; the pool fee reimburses it.
{ call, proof } artifact.
Execute a private swap
Implement the prover
Theprover is where the cryptography lives. It receives a PrivateSwapPlan (sell/buy tokens, amounts, executorAddress, inner calls, pool fee) and returns the proven call. With the privacy SDK’s transfers builder:
Open is a privacy SDK sentinel that opens a note for the swap output, whose amount is only known after execution. The inner calls are serialized with starknet.js’s transaction.fromCallsToExecuteCalldata_cairo1; the executor expects [buyToken, ...serializedCalls, openNoteId].
Alternatively, a STRK20-capable wallet (e.g. Ready or Xverse) can produce the same artifact via WalletAccountV6.strk20PrepareInvoke: describe the same four actions and map the returned call and proof to PrivateSwapCallAndProof. The wallet keeps the keys; the dapp only describes actions.
Manual control
executePrivateSwap wraps three functions you can also call yourself:
Key parameters
The SDK’s private swap functions always run in thesponsored_private fee mode: the relayer pays gas, the user pays the pool fee from their private balance.
Token used to pay the pool fee (e.g. STRK, ETH, USDC). The paymaster converts the base STRK amount to this token via its price oracle.
Relayer priority tip.
The privacy pool contract address. The SDK exports the pools whitelisted by the paymaster:
PRIVACY_POOL_ADDRESS (mainnet) and SEPOLIA_PRIVACY_POOL_ADDRESS.Your proving backend:
buildAndProve(plan) returns the proven { call, proof }. The SDK never handles private keys, notes, or proof generation.Optional fail-fast check: when provided, it is compared to
quote.chainId before any paymaster or proving round-trip.Portal API key, the same one used for gasfree — the paymaster requires it for the sponsored modes. Server-side only: do not ship it in client code. Browser dapps should split the flow:
buildPrivateSwapFee and submitPrivateSwap behind server endpoints, proving (prover) client-side with the user’s wallet.Related
Privacy Overview
Privacy pool, fees, and transaction types
Get Quotes
Fetch solver-optimized swap quotes