Skip to main content
A Shield Swap trade has two transactions. The request spends the input record and writes a pending output. The claim delivers the output and any unspent input as token records. Handle both transactions in your integration. The trade settles once the claim is accepted and the returned records are available.

Plan the route

In v0.12.1, you can request a quote with client.quote({ from, to, amountIn: "1", slippageBps: 50 }) and submit it with client.swap({ quote }). See the Quickstart for a complete example. Use the manual steps below if you need to supply execution parameters yourself. planSwap resolves token metadata, requests a route and quote, checks each pool against current chain controls, applies a slippage floor, and fetches the required program imports.
Amounts passed to transaction actions are raw base units. 50 basis points means 0.5 percent slippage.

Submit the request

Use swap for one pool and swapMultiHop for a route with two or more pools.
The returned handle contains the data needed to claim the output. A local client with fileBlindedIdentityStore records it before the action returns. If you do not use that store, save the handle in your own database before ending the request flow. Do not submit another request because a confirmation wait timed out. Check the transaction and mapping state first. A second submission can spend another record and create another trade.

Claim the output

The pending output becomes readable after the request finalizes. Both route types use claimSwapOutput.
amountOut is the received output. amountRemaining is the unused portion of the original input. Wrapped assets are paid out as records of the underlying asset. For a multi-hop route, each later hop must consume its intermediate input. A partial fill in a later hop rejects the route. Only unused original input can appear as the final refund.

Verify settlement

Use publicClient.getConfirmedTransaction({ id }) for both the request and claim transaction IDs. Both must report accepted. Then check that client.getSwapOutput({ swapId: handle.swapId }) returns null and that the account has the claim’s returned token records. An absent pending output or an empty getUnclaimedSwaps() result does not establish settlement on its own. Match the accepted claim to the swap ID and its output commitments to the decrypted records. See Verify swap settlement for the complete quickstart verifier.

Recover pending claims

For long-running local clients, check the configured identity store at startup.
getUnclaimedSwaps reads swap_outputs from chain. It returns per-token totals and handles that can be claimed from the store alone. In v0.12.1, claimSwapOutput resolves program imports from the output tokens automatically. Older records without a complete handle may require reconcileSwapHistory().

Run concurrent swaps safely

The composed client reserves a distinct confidential address for each local swap. Use one store and one writer for each local account. A file store protects reservations across restarts, but it does not coordinate multiple processes or machines. Two concurrent swaps cannot spend the same input token record. Using different input tokens avoids that collision. For the same token, serialize record selection and submission or reserve distinct records in your own transaction queue. A connected wallet manages its own confidential addresses and record requests. Follow the wallet’s pending-transaction model and wait for a terminal state before reusing any record. See Trader workflow, output claims and refunds, and failures and recovery for the protocol rules behind these actions.