<!-- tempo-docs-context -->
> Source: [/docs/guide/stablecoin-dex](https://tempo.xyz/developers/docs/guide/stablecoin-dex.md)
> Section: [Tempo EVM](https://tempo.xyz/developers/docs/development.md). Build on Tempo EVM: wallets and keys, transactions and fees, TIP-20 Tokens, contracts, exchange, network details, nodes, protocol specifications, and changelog.
> [Documentation index](https://tempo.xyz/developers/llms.txt) · [Docs skill](https://tempo.xyz/developers/SKILL.md)

> Tempo MCP: Use `search`, `find_pages`, `read_page`, and `code` at `https://mcp.tempo.xyz` for Tempo and related documentation.
> If an indexed page is missing or reflects an older site, read this site’s [documentation index](https://tempo.xyz/developers/llms.txt) and Markdown pages directly.

<span id="stablecoin-dex" />

<span id="exchange-stablecoins-on-the-tempo-dex" />

<span id="exchange" />

# Stablecoin DEX

Swap stablecoins on Tempo through the onchain orderbook, or provide liquidity by placing orders. Use [Routes](https://tempo.xyz/developers/docs/routes) when you need to move funds between networks.

:::info[Interactive walkthrough]
Try the [swap walkthrough](https://tempo.xyz/developers/docs/guide/stablecoin-dex/executing-swaps) with a test wallet, then build the swap form in your application.
:::

<span id="stablecoin-exchange-paths" />

<span id="swap-or-provide-liquidity" />

## Swap stablecoins

Choose the input and output tokens, request a quote, and set the minimum output your application accepts. This example swaps one AlphaUSD for BetaUSD on Moderato, using the [Network example setup](https://tempo.xyz/developers/docs/network/examples). The pair needs available liquidity.

::::steps
### Get a quote

The quote is an integer amount of the output token in base units.

:::code-group
```ts [Viem]
const quote = await client.dex.getSellQuote({
  tokenIn: alphaUsd,
  tokenOut: betaUsd,
  amountIn: 1_000_000n,
})
```

```bash [CLI]
QUOTE=$(cast call "$DEX" \
  'quoteSwapExactAmountIn(address,address,uint128)(uint128)' \
  "$TOKEN" "$BETA_TOKEN" 1000000 --rpc-url "$RPC_URL" --json | jq -r '.[0]')
```

```ts [Wagmi]
  const quote = await Actions.dex.getSellQuote(config, {
    tokenIn: alphaUsd,
    tokenOut: betaUsd,
    amountIn: 1_000_000n,
  })
```

```python [Python]
from network_config import ALPHA_USD, BETA_USD, dex

quote = dex.functions.quoteSwapExactAmountIn(
    ALPHA_USD, BETA_USD, 1_000_000
).call()
```
:::

<span id="approve-the-input-token" />

The Stablecoin DEX can pull TIP-20 input tokens through the protocol's implicit-approval path. A separate token approval is not required. The pull still enforces balance, transfer-policy, and access-key spending-limit checks.

### Submit the swap

This example accepts at most 0.5% less output than the quote. A quote does not reserve liquidity; the transaction enforces `minAmountOut` and reverts if the limit cannot be met.

:::code-group
```ts [Viem]
const { receipt } = await client.dex.sellSync({
  tokenIn: alphaUsd,
  tokenOut: betaUsd,
  amountIn: 1_000_000n,
  minAmountOut: (quote * 995n) / 1000n,
})
console.log(receipt.transactionHash)
```

```bash [CLI]
MIN_OUT=$((QUOTE * 995 / 1000))
cast send "$DEX" 'swapExactAmountIn(address,address,uint128,uint128)' \
  "$TOKEN" "$BETA_TOKEN" 1000000 "$MIN_OUT" \
  --rpc-url "$RPC_URL" --tempo.fee-token "$TOKEN" --interactive
```

```ts [Wagmi]
  const result = await Actions.dex.sellSync(config, {
    tokenIn: alphaUsd,
    tokenOut: betaUsd,
    amountIn: 1_000_000n,
    minAmountOut: (quote * 995n) / 1000n,
  })
  console.log(result.receipt.transactionHash)
```

```python [Python]
from pytempo.contracts import StablecoinDEX
from network_config import make_transaction, submit

call = StablecoinDEX.swap_exact_amount_in(
    token_in=ALPHA_USD, token_out=BETA_USD,
    amount_in=1_000_000, min_amount_out=quote * 995 // 1000,
)
receipt = submit(make_transaction((call,)))
print(receipt["transactionHash"].hex())
```
:::
::::

For direct HTTP submission, [sign locally and broadcast through JSON-RPC](https://tempo.xyz/developers/docs/network/transactions#sign-and-submit). [Quote tokens](https://tempo.xyz/developers/docs/protocol/exchange/quote-tokens) explains how supported trading pairs connect.

## Provide liquidity

Place a limit order to trade at a chosen price, or use a flip order to place a reverse order after a fill. The [liquidity guide](https://tempo.xyz/developers/docs/guide/stablecoin-dex/providing-liquidity) covers token approvals, order placement, querying, and cancellation with a working demo.

Fee AMM reserves serve a different purpose: converting transaction fees into a validator's preferred token. Use [Provide fee liquidity](https://tempo.xyz/developers/docs/guide/stablecoin-dex/managing-fee-liquidity) for that workflow.

<span id="understand-trading-pairs-and-balances" />

## Account and exchange balances

Balances recorded by the DEX contract are distinct from an account's TIP-20 balance. Read [DEX balances](https://tempo.xyz/developers/docs/protocol/exchange/exchange-balance) before showing available funds or reconciling orders. The [DEX specification](https://tempo.xyz/developers/docs/protocol/exchange/spec) defines order, swap, and settlement behavior.
