Instant Confidential Swaps
Quote, sign, and settle single-slot confidential swaps from a shielded balance in /trade or via @mera/sdk.
An instant confidential swap converts one shielded asset into another inside the active Ring in a single Solana transaction (settle_confidential_swap). Neither your input size nor your post-trade balance appears in plaintext on the public ledger.
Prerequisites
- A connected Solana wallet (or
MeraSignerin Node.js) with access to the target Ring. - At least one unspent
CommitmentNotein the input mint covering your swap size. If your shielded balance is zero, deposit first in Shielding Assets.
Executing a swap in /trade
- Open Terminal and confirm your active Ring in the top bar.
- Select the Swap tab and pick a pair (
SOL / USDC,wBTC / USDC,wETH / USDC, orJitoSOL / SOL) and side (sellbase for quote, orbuybase with quote). - Enter your input amount. Mera calls
POST /v1/swap/quoteand returns a sealed quote valid for 25 seconds, showingexecutionPrice,outputAmount,minOutputAmount(bounded byslippageBps, default50bps),feeAmount(0.10%default), and the expiry countdown. - Press Execute Swap before the countdown expires. Mera calls
POST /v1/swap/buildto assemble the unsigned v0 transaction, your wallet signs first as taker and fee payer, andPOST /v1/transactions/submitattaches the maker co-signature and relays the transaction. - Once confirmed, the terminal displays the settlement status, measured finality in milliseconds, updated shielded balances, and a Copy TVK button in the recent fills table.
Executing a swap with @mera/sdk
mera.executeSwap runs quoteSwap, buildSwap, signs the v0 transaction with your signer, and submits it in one call:
ts
import { createMeraClient, keypairSigner } from '@mera/sdk'
const mera = createMeraClient({
apiUrl: 'http://127.0.0.1:36102',
signer: keypairSigner(myKeypair),
})
const { quote, submission } = await mera.executeSwap({
ringId: 'ring-default',
pairId: 'SOL-USDC',
side: 'sell',
inputAmount: '2000000000', // 2 SOL (9 decimals)
slippageBps: 50, // 0.50% max slippage (1..500)
})
console.log('Quote ID:', quote.quoteId)
console.log('Net output (base units):', quote.outputAmount)
console.log('Protocol fee (base units):', quote.feeAmount, `(${quote.feeBps} bps)`)
console.log('Signature:', submission.signature)
console.log('Slot:', submission.slot, 'Finality:', submission.finalityMs, 'ms')
console.log('TVK:', submission.tvk)If you want to inspect the quote before signing, call mera.api.quoteSwap(...), verify quote.executionPrice and quote.minOutputAmount, then call mera.api.buildSwap({ wallet, quoteId: quote.quoteId }) and submit the signed transaction via mera.api.submitTransaction(...).
Fee and output math
grossOutputis computed frominputAmountandexecutionPrice.feeAmount = floor(grossOutput * feeBps / 10_000)is transferred on chain from the Ring's outputShieldedVaulttoProtocolConfig.fee_recipient(Token & Fee Flow).outputAmount = grossOutput - feeAmountis credited to your new outputCommitmentNotePDA.minOutputAmount = outputAmount - floor(outputAmount * slippageBps / 10_000).
Handling errors
| Code | HTTP | Cause and action |
|---|---|---|
QUOTE_EXPIRED | 409 | More than 25 seconds elapsed between quote and build, or the quote was already used. Request a fresh quote. |
INSUFFICIENT_SHIELDED_BALANCE | 400 | No single unspent CommitmentNote in the Ring covers inputAmount. Shield more tokens in /balance. |
PAIR_NOT_SUPPORTED | 400 | pairId is not in the active pairs list (GET /v1/pairs). |
RING_ACCESS_DENIED / RING_FROZEN | 403 | Wallet is not allowlisted in this Custom Ring, or the Ring or member is frozen. |
UPSTREAM_UNAVAILABLE | 502 | Maker shielded output inventory is temporarily below the requested size. Retry shortly or reduce size. |