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

# Stablecoin Swaps via Paxos Labs Transit

> Enable same-chain and cross-chain stablecoin swaps with Paxos Labs Transit and Para embedded wallets.

Combine Para's viem account infrastructure with the Paxos Labs Transit API to enable same-chain and cross-chain stablecoin swaps, all from a Para-powered wallet.

## What You'll Learn

* Create a Para-backed viem account and wallet client
* Discover and quote available Transit routes
* Authorize an offer token and submit a Transit order
* Track the order until it reaches a terminal state

## What You Need

You need these components to integrate Transit with Para:

* **Para SDK** for creating and managing wallets
* **An HTTP client** such as `fetch` or Axios. Transit is a REST API and requires no API authentication; all endpoints are public
* **EVM-compatible chain** such as Ethereum Mainnet (chain ID 1) or RH Chain (chain ID 4663)
* **Native gas** in the Para wallet to cover the swap transaction plus Transit's cross-chain messaging fee

## Step-by-Step Integration

### Step 1: Install Dependencies

```bash theme={null}
npm install @getpara/viem-v2-integration @getpara/react-sdk viem
```

### Step 2: Initialize Para and Create the Wallet Clients

Complete authentication before signing.

```typescript theme={null}
import {
  createParaViemAccount,
  createParaViemClient,
} from "@getpara/viem-v2-integration";
import { ParaWeb } from "@getpara/react-sdk";
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";

// Initialize Para (complete authentication before signing)
const para = new ParaWeb("YOUR_PARA_API_KEY");

const account = createParaViemAccount({ para });

const walletClient = createParaViemClient({
  para,
  walletClientConfig: {
    account,
    chain: mainnet,
    transport: http("https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY"),
  },
});

const publicClient = createPublicClient({
  chain: mainnet,
  transport: http("https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY"),
});
```

### Step 3: Discover Available Transit Routes

Query `GET /v1/transit/routes` to find supported asset pairs between your source and destination chains. Routes can be narrowed with AIP-160 filter expressions on `sourceChainId`, `destinationChainId`, `offerAsset`, and `wantAsset`.

```typescript theme={null}
const res = await fetch(
  "https://api.paxoslabs.com/v1/transit/routes?filter=" +
    encodeURIComponent("sourceChainId=1"),
);
const { routes } = await res.json();

const route = routes[0];
// route.offerAsset       token address on the source chain
// route.wantAsset        token address on the destination chain
// route.minOrderSize     minimum order size in offer-asset base units
//                         (for example, 35000000 = $35 for a 6-decimal token like USDC)
// route.tokenMetadataMap token details indexed by lowercase address
```

Orders below `minOrderSize` are rejected with `400 INVALID_ARGUMENT`.

### Step 4: Check Authorization for the Offer Token

Call `GET /v3/core/authorization` to determine how the TransitStation contract gets spending permission. The TransitStation address is returned as `transaction.to` on any order quote (see step 5), so fetch an initial quote to obtain it. Three outcomes are possible:

```typescript theme={null}
const offerAmount = "100000000"; // 100 USDC (6-decimal base units)

const authRes = await fetch(
  "https://api.paxoslabs.com/v3/core/authorization?" +
    new URLSearchParams({
      spenderAddress: TRANSIT_STATION_ADDRESS, // transaction.to from a prior quote
      tokenAddress: route.offerAsset,
      amount: offerAmount,
      userAddress: account.address,
      chainId: "1",
    }),
);
const auth = await authRes.json();

let permitSignature: `0x${string}` | undefined;
let permitDeadline: string | undefined;

if (auth.method === "permit") {
  // Token supports EIP-2612. Para signs the permit off-chain (gasless).
  permitSignature = await walletClient.signTypedData({
    account,
    domain: auth.permitData.domain,
    types: auth.permitData.types,
    primaryType: "Permit",
    message: auth.permitData.value,
  });
  permitDeadline = auth.permitData.deadline;
} else if (auth.method === "approval") {
  // Standard ERC-20 approve transaction (raw calldata sent to the token contract)
  const approvalHash = await walletClient.sendTransaction({
    account,
    to: route.offerAsset,
    data: auth.approvalTransaction.encoded,
  });
  await publicClient.waitForTransactionReceipt({ hash: approvalHash });
}
// "already_approved" means sufficient allowance exists, so proceed to the quote.
```

### Step 5: Get an Order Quote and Submit the Transit Order

`GET /v1/transit/orders/quote` returns ABI-encoded `submitOrder` calldata, including the cross-chain messaging fee in `value`. Broadcast it directly with the Para wallet client:

```typescript theme={null}
const quoteParams = new URLSearchParams({
  userAddress: account.address, // wallet receiving destination funds
  offerAmount, // base units, minimum $35 USD equivalent
  offerAsset: route.offerAsset,
  wantAsset: route.wantAsset,
  sourceChainId: "1",
  destinationChainId: String(route.destinationChainId),
});
if (permitSignature && permitDeadline) {
  quoteParams.set("permitSignature", permitSignature);
  quoteParams.set("permitDeadline", permitDeadline);
}

const quoteRes = await fetch(
  `https://api.paxoslabs.com/v1/transit/orders/quote?${quoteParams}`,
);
const quote = await quoteRes.json();
// quote.amountOut          net amount after fees (want-asset base units)
// quote.totalFees          sum of protocol and integrator fees
// quote.estimatedLatencyMs expected delivery time

const hash = await walletClient.sendTransaction({
  account,
  to: quote.transaction.to, // TransitStation contract
  data: quote.transaction.data, // ABI-encoded submitOrder calldata
  value: BigInt(quote.transaction.value), // native token messaging fee
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
// The receipt contains an OrderSubmitted event with the order ID,
// a 32-byte hex hash used to track the order in step 6.
const orderId = "0x..."; // from the OrderSubmitted event in receipt.logs
```

Optional quote parameters include `integratorFee` plus `integratorFeeReceiver` to charge your own fee, `distributorCode` as a 32-byte tracking code, and `responseFormat` with `encoded`, `full`, or `structured` values.

### Step 6: Track the Order to Completion

Poll `GET /v1/transit/orders/:orderId` with the order ID from the `OrderSubmitted` event until it reaches a completed state:

```typescript theme={null}
const TERMINAL = ["PROCESSED", "REMOVED"];

async function waitForOrder(orderId: string) {
  while (true) {
    const res = await fetch(
      `https://api.paxoslabs.com/v1/transit/orders/${orderId}`,
    );
    const { order } = await res.json();

    if (TERMINAL.includes(order.status)) return order;
    await new Promise((resolve) => setTimeout(resolve, 10_000));
  }
}

const order = await waitForOrder(orderId);
// PENDING_BRIDGE order submitted, awaiting processing
// PROCESSING     order is being fulfilled
// PROCESSED      order complete, funds delivered
// REMOVED        order removed from the queue
```

## Why Combine Para and Transit

| Feature        | Benefit                                                                                           |
| -------------- | ------------------------------------------------------------------------------------------------- |
| Para wallets   | Instant onboarding, MPC-secure, white-label                                                       |
| Transit orders | Same-chain and cross-chain stablecoin swaps, server-side calldata generation, no API key required |

Together, you can offer one-click stablecoin swaps and bridging in your app. Para handles keys and signing, while Transit handles routing, quoting, and cross-chain settlement.

## Example Use Cases

* **In-App Bridging**: Let users move stablecoins between Ethereum and RH Chain from an embedded Para wallet with no external bridge UI required
* **Swap-to-Deposit Flows**: Chain a Transit swap with an [Amplify deposit](/v3/walkthroughs/amplify) so users can enter a yield position from any supported stablecoin on any supported chain
* **Integrator Monetization**: Attach an `integratorFee` and `distributorCode` to each order to earn revenue and attribute volume from your app's swap flow

## Related Resources

<CardGroup cols={3}>
  <Card title="Paxos Amplify" icon="chart-line" href="/v3/walkthroughs/amplify">
    Add stablecoin yield deposits and withdrawals to a Para-powered wallet
  </Card>

  <Card title="Para Viem Integration" icon="plug" href="/v3/react/guides/web3-operations/evm/setup-libraries">
    Set up Para wallets with viem for EVM transaction signing
  </Card>

  <Card title="Paxos Labs" icon="arrow-up-right-from-square" href="https://www.paxoslabs.com">
    Learn more about Paxos Labs stablecoin infrastructure
  </Card>
</CardGroup>
