> ## Documentation Index
> Fetch the complete documentation index at: https://docs.privacyboost.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Swaps

# Private Swaps

Swap one shielded token for another without leaving the pool. A swap spends a
private note of the input token, routes the trade through the external call
gateway to a server-quoted aggregator route (1inch), and credits a private note
of the output token. If the trade can't settle, the input token is refunded
instead. Like [earn](https://docs.privacyboost.io/sdk/concepts/earn.md), swaps are a gateway feature that each
deployment enables separately.

> [!NOTE]
>
> `swap quote`, `swap from-quote`, and `swap execute` need your wallet private
> key on each run (the CLI prompts for it, or reads `PRIVATE_KEY`).
> `swap status` runs on a saved `login` session.

## Finding Token IDs

Swaps take registry token ids, not addresses. `privacy-boost tokens list`
prints each token's id and decimals. The input token must advertise a
`1inch-classic` swap capability on the deployment.

## Quote, Review, Submit

Fetch a quote and save it:

```bash theme={null}
privacy-boost swap quote \
  --input-token-id 1 \
  --output-token-id 2 \
  --amount 0.5 \
  --human \
  > quote.json
```

The quote is always printed as JSON. The fields to review are `inputAmount`,
`expectedOutputAmount`, `minOutputAmount` (the slippage-bound minimum that gets
signed), and `priceImpactBps`, all in raw token units. `--max-slippage-bps`
sets how far below the quoted output a fill may land (default 50). With
`--human`, `--decimals` is the input token's decimals (default 18).

Submit exactly that quote:

```bash theme={null}
privacy-boost swap from-quote --quote-file quote.json
```

`from-quote` reuses the quote's route and signed minimum byte for byte, so the
economics you reviewed are the ones signed. It refuses a quote older than two
minutes; fetch a new one if yours has expired. `--quote '<json>'` passes the
quote inline instead of from a file. It is never read from stdin.

Output:

```
Swap submitted (1inch-classic)
  Request ID:   <request-id>
  Input token:  1
  Output token: 2
  Amount:       500000000000000000
  Fee:          <fee>
  Expected out: <expected-output>
  Min out:      <minimum-output>
  Expires at block 12345678
Track credit with: privacy-boost swap status <request-id>
```

## One-Shot Swaps

`swap execute` fetches a fresh quote and submits it in one step, so nobody
reviews the route being signed. It therefore requires a floor:

```bash theme={null}
privacy-boost swap execute \
  --input-token-id 1 \
  --output-token-id 2 \
  --amount 0.5 \
  --human \
  --min-acceptable-output 1450000000
```

`--min-acceptable-output` is the least you accept, in raw output-token units,
and must be non-zero. It is checked against the quote's guaranteed minimum,
not its expected output, so leave room for slippage: a floor at the expected
output rejects every quote. Prefer `quote` and `from-quote` when a person
reviews the trade.

## Tracking a Swap

```bash theme={null}
privacy-boost swap status <request-id>
```

The status is printed as JSON and includes the gateway settlement and credit
projection. `creditStatus=completed` means the output note was credited, and
`creditStatus=rescued` means the escrow was paid to the rescue destination.
Both end the wait for private credit.

In `history`, a swap appears as two rows, one per epoch.
`privacy-boost history --collapse-gateway` shows it as one.

## Next Steps

* [Commands Reference](https://docs.privacyboost.io/sdk/cli/guides/commands.md#swap-commands)
* [Transaction History](https://docs.privacyboost.io/sdk/cli/guides/transactions.md)
* [Earn](https://docs.privacyboost.io/sdk/concepts/earn.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.