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

# Relay Bridge with Callback

> Bridge tokens across chains using Relay with dynamic amount resolution and post-bridge execution

export const date_0 = "2025-02-03"

This workflow demonstrates bridging tokens using Relay protocol with automatic post-bridge execution. Relay uses a placeholder-based design for dynamic amount resolution, making it ideal for complex workflows where amounts are determined at execution time.

```mermaid theme={null}
flowchart LR
    subgraph ethereum ["🌐 Ethereum"]
        USDC((USDC)) -->|route| ETH_ETH((ETH))
        ETH_ETH --> A1(( ))
    end

    A1 -.->|relay<br/>bridge| B1

    subgraph arbitrum ["🔷 Arbitrum"]
        B1(( )) -->|balance| ETH_ARB((ETH))
        ETH_ARB -->|wrap| WETH((WETH))
    end
```

**Route Mechanics:**

This bundle swaps USDC to ETH, bridges to Arbitrum via Relay, then wraps to WETH:

* Swap USDC to native ETH on Ethereum using Enso routing
* Bridge ETH from Ethereum to Arbitrum using Relay (supports native tokens)
* Check ETH balance on Arbitrum after successful bridge
* Wrap ETH to WETH on Arbitrum

```typescript relayBridgeWithCallback.ts theme={null}
import { EnsoClient } from "@ensofinance/sdk";

// Chain IDs
const ETHEREUM_ID = 1;
const ARBITRUM_ID = 42161;

// Common addresses
const WALLET_ADDRESS = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";

// Token addresses
const USDC_ETHEREUM = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
const WETH_ARBITRUM = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1";
const NATIVE_TOKEN = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";

const client = new EnsoClient({
  apiKey: process.env.ENSO_API_KEY!,
});

const bundle = await client.getBundleData(
  {
    chainId: ETHEREUM_ID,
    fromAddress: WALLET_ADDRESS,
    routingStrategy: "router",
  },
  [
    // Step 1: Swap USDC to ETH on Ethereum
    {
      protocol: "enso",
      action: "route",
      args: {
        tokenIn: USDC_ETHEREUM,
        tokenOut: NATIVE_TOKEN,
        amountIn: "10000000", // 10 USDC
      },
    },
    // Step 2: Bridge ETH to Arbitrum via Relay
    {
      protocol: "relay",
      action: "bridge",
      args: {
        primaryAddress: "0xa5f565650890fba1824ee0f21ebbbf660a179934",
        destinationChainId: ARBITRUM_ID,
        tokenIn: NATIVE_TOKEN, // Relay supports native tokens
        amountIn: { useOutputOfCallAt: 0 },
        receiver: WALLET_ADDRESS,
        callback: [
          // Step 3: Check ETH balance on Arbitrum
          {
            protocol: "enso",
            action: "balance",
            args: {
              token: NATIVE_TOKEN,
            },
          },
          // Step 4: Wrap ETH to WETH on Arbitrum
          {
            protocol: "wrapped-native",
            action: "deposit",
            args: {
              primaryAddress: WETH_ARBITRUM,
              tokenIn: NATIVE_TOKEN,
              tokenOut: WETH_ARBITRUM,
              amountIn: { useOutputOfCallAt: 0 },
            },
          },
        ],
      },
    },
  ],
);

return bundle;
```

**Important Considerations:**

* Relay supports both ERC20 and native token bridging
* No callback data limit - uses placeholder-based design for dynamic amounts
* Fee is taken from the bridged token amount (no separate fee token)
* API-based quote system determines optimal routing
* For Relay, `primaryAddress` is the token address itself

## Key Differences from Other Bridges

| Feature           | Relay                  | CCIP              | Stargate           | CCTP                      |
| ----------------- | ---------------------- | ----------------- | ------------------ | ------------------------- |
| Native Token      | Yes                    | No                | Yes                | No (USDC only)            |
| Callback Limit    | Unlimited              | \~30KB            | \~9.5KB            | Not supported             |
| Fee Token         | Token itself           | Native            | Native             | USDC (from minted amount) |
| Amount Resolution | Dynamic (placeholders) | Pre-computed      | Pre-computed       | Pre-computed              |
| Token Coverage    | ERC20 + native         | Whitelisted ERC20 | OFT-enabled tokens | USDC only                 |

## Resources

* [Crosschain Routing Guide](/pages/build/get-started/crosschain-routing) - Complete guide to crosschain operations
* [Bridge Action Reference](/pages/build/reference/actions#bridge) - Technical details on bridge parameters

<div className="text-right text-xs gray-200 font-semibold w-full" style={{marginTop: '0'}}>
  <p style={{
        color: "#b2b2b2"  
    }}>Updated {date_0}</p>
</div>
