---
# System prepended metadata

title: SDK Swap/Bridge Mode

---

---
title: Swap/Bridge Mode
description: Enable users to swap or bridge assets directly to their own wallet.
---

# Swap/Bridge Mode

Users convert assets for themselves. Funds are routed back to the user's connected wallet.

## Overview

Swap/Bridge Mode is the simplest integration pattern. Users connect their wallet, select an asset to swap or bridge, and receive the output in the same wallet. No destination address configuration is required: the SDK automatically routes funds to the connected wallet.

**When to use this mode:**
- In-app token swaps
- Cross-chain bridging
- Portfolio rebalancing
- Any flow where users are converting assets for themselves

## How It Works

```
┌─────────────────┐      ┌─────────────────┐      ┌─────────────────┐
│   User's EOA    │ ──▶  │    Trustware    │ ──▶  │   User's EOA    │
│  (Source Wallet)│      │  Routing Engine │      │  (Same Wallet)  │
└─────────────────┘      └─────────────────┘      └─────────────────┘
     USDT on                                           USDC on
     Ethereum                                          Base
```

Since `toAddress` is omitted, the SDK defaults to the connected wallet as the destination.

---


## Preset Destination Output Example

If you want to guide users toward a specific output (e.g., your app uses USDC on Base), preset the destination chain and token:


```typescript
import { TrustwareProvider, TrustwareWidget } from "@trustware/sdk";
import type { TrustwareConfigOptions } from "@trustware/sdk";

const config: TrustwareConfigOptions = {
  apiKey: "your-api-key",
  routes: {
    toChain: "8453",  // Base
    toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
    defaultSlippage: 1,
  },
  messages: {
    title: "Swap to USDC",
    description: "Convert any token to USDC on Base.",
  },
};

export function SwapWidget() {
  return (
    <TrustwareProvider config={config}>
      <TrustwareWidget />
    </TrustwareProvider>
  );
}
```

In this example:
- User pays with USDT on Ethereum (or any asset they hold)
- User receives USDC on Base in their same wallet

---

## Full Configuration Reference

```typescript
import type { TrustwareConfigOptions } from "@trustware/sdk";

const config: TrustwareConfigOptions = {
  // Required
  apiKey: "your-api-key",

  // Route settings (all optional for Swap/Bridge Mode)
  routes: {
    toChain: "8453",                                      // Preset destination chain
    toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Preset destination token
    fromToken: "0xdAC17F958D2ee523a2206206994597C13D831ec7", // Preset source token 
    defaultSlippage: 1,                                   // Slippage tolerance (default: 1%)
    options: {
      fixedFromAmount: "100",      // Lock input amount (optional)
      minAmountOut: "99",          // Minimum output (optional)
      maxAmountOut: "101",         // Maximum output (optional)
    },
  },

  // Wallet detection (optional, default: false)
  autoDetectProvider: false,

  // UI customization (optional)
  theme: {
    primaryColor: "#FCB514",
    backgroundColor: "#000000",
    borderColor: "#FCB514",
    secondaryColor: "#FFFFFF",
    textColor: "#FFFFFF",
    radius: 16,
  },
  messages: {
    title: "Swap",
    description: "Convert any token to any token.",
  },
};
```

### Route Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `toChain` | `string` | ✅ | - | Destination chain ID |
| `toToken` | `string` | ✅ | - | Destination token address |
| `fromToken` | `string` | ❌ | User selects | Source token address |
| `defaultSlippage` | `number` | ❌ | `1` | Slippage tolerance (percentage) |
| `options.fixedFromAmount` | `string \| number` | ❌ | - | Lock the input amount |
| `options.minAmountOut` | `string \| number` | ❌ | - | Minimum acceptable output |
| `options.maxAmountOut` | `string \| number` | ❌ | - | Maximum output cap |

---

## Wallet Connection

### Using an Existing Connection

If your app already manages wallet connections (via Wagmi, RainbowKit, etc.), set `autoDetectProvider: false` or omit it entirely. The widget will use the wallet your app has already connected.

```typescript
import { WagmiProvider, createConfig, http } from "wagmi";
import { base } from "wagmi/chains";
import { TrustwareProvider, TrustwareWidget } from "@trustware/sdk";

const wagmiConfig = createConfig({
  chains: [base],
  transports: { [base.id]: http() },
});

const trustwareConfig = {
  apiKey: "your-api-key",
  autoDetectProvider: false, // Use Wagmi's connected wallet
};

export function App() {
  return (
    <WagmiProvider config={wagmiConfig}>
      <TrustwareProvider config={trustwareConfig}>
        <TrustwareWidget />
      </TrustwareProvider>
    </WagmiProvider>
  );
}
```

### Letting the Widget Handle Connection

If you want the widget to handle wallet discovery and connection, set `autoDetectProvider: true`. The widget will detect available wallets via EIP-6963/EIP-1193 and prompt the user to connect.

```typescript
const config = {
  apiKey: "your-api-key",
  autoDetectProvider: true, // Widget handles wallet connection
};
```

---

## Liquidity Considerations

:::info
Swap and bridge routes depend on available liquidity across DEXs and bridges. Routes with deeper liquidity (e.g., USDC, ETH, major stablecoins) will have better execution with lower slippage. For less liquid pairs, consider increasing the `defaultSlippage` tolerance.
:::

---

## Summary

| Setting | Value for Swap/Bridge Mode |
|---------|---------------------------|
| `toAddress` | omit - defaults to connected wallet |
| `autoDetectProvider` | `false` if app manages connection, `true` if widget should handle it |
| Required config | `apiKey` only |

→ [Back to configuration Modes / SDK OVERVIEW](https://hackmd.io/@trustware/B1zaIVkSbe)
