> ## 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.

# Same-chain intents

> Buy xStocks and Ondo GM tokens asynchronously on the same chain, track execution with /intent/status, and handle refunds.

A same-chain buy of an xStock on Optimism or an Ondo GM token on BSC normally runs as one atomic transaction. Because these assets are minted against short-lived RFQ quotes, an atomic transaction can revert if the quote expires before it mines.

With `sameChainIntent=true`, the Route API splits the trade into two transactions. Your transaction swaps `tokenIn` into the settlement token and hands it to a one-time intent address. Enso then buys `tokenOut` in a second transaction on a fresh quote and sends it to `receiver`.

> [!NOTE]
>
> Same-chain intents are separate from [async redeems](https://docs.enso.build/pages/build/get-started/async-redeems.md) (`allowAsync`). `allowAsync` is for vault withdrawals that pay out later and cannot be combined with intents.

## How it works

```mermaid theme={null}
flowchart LR
    A["Transaction 1<br/>Swap tokenIn to settlement token"] --> B["Intent address<br/>Publishes intent and holds funds"]
    B -. "executes on a fresh quote" .-> C["Transaction 2<br/>Buy tokenOut for receiver"]
    B -. "if buy fails past 5-min deadline" .-> D["Refund settlement token<br/>to refundReceiver or receiver"]
```

1. Your user signs and submits transaction 1 on `chainId`. If `tokenIn` is not already the settlement token, transaction 1 swaps it into the settlement token first.
2. Transaction 1 checks that the amount meets the intent trigger and that the block timestamp is at or before `validUntil`, publishes the intent on-chain, and transfers the settlement token to `intent.address`.
3. Enso observes the published intent, requests a fresh quote, buys `tokenOut`, and sends at least `minAmountOut` to `receiver` in transaction 2.
4. If the buy cannot fill before the 5-minute deadline, the settlement token is refunded to `refundReceiver`, or to `receiver` when `refundReceiver` is not set.

Delivery is asynchronous. `tokenOut` arrives in transaction 2, not transaction 1.

## Supported assets

Same-chain intents apply when `tokenOut` is a supported mintable position with a single underlying token and `tokenIn` is not one of those positions. Same-chain intent execution must also be enabled on `chainId`.

| Asset | Chain | Settlement token |
| - | - | - |
| xStocks and wrapped xStocks | Optimism (`10`) | USDC |
| Ondo GM tokens | BSC (`56`) | USDT |

Selling an xStock or Ondo GM token (passing one as `tokenIn`) stays on the normal atomic route because selling still requires an RFQ quote in transaction 1.

## Request

Same-chain intents are available on `GET` and `POST /api/v1/shortcuts/route`. They are not available on `/quote` or the public Bundle API.

| Parameter | Requirement |
| - | - |
| `sameChainIntent` | Must be `true`. Defaults to `false`. Ignored on cross-chain routes. |
| `useIntentAddress` | Not needed. Sending `false` together with `sameChainIntent=true` returns a `400`. |
| `receiver` | Required. EVM address that receives `tokenOut`. Missing it returns a `400`. |
| `refundReceiver` | Optional. EVM address on `chainId` that receives the settlement token if the intent expires. Defaults to `receiver`. |
| `slippage` | Slippage tolerance in basis points, greater than `"0"`. Defaults to `"50"` (0.5%). Do not pass `minAmountOut`. |
| `routingStrategy` | Defaults to `"router"`. |
| `ignoreAggregators` | Optional. Applied to both transaction 1 and transaction 2. |

Unsupported requests silently fall back to the normal atomic route, so always check for `intent` in the response.

```typescript theme={null}
const route = await response.json();

if (route.intent) {
  // same-chain intent: submit route.tx, then track with GET /api/v1/intent/status
} else {
  // normal atomic route: tokenOut arrives in route.tx
}
```

## Example: buy an xStock on Optimism

Set `ENSO_API_KEY` to your API key, `ADDRESS` to the user's wallet, and `XSTOCK_TOKEN` to the target xStock or wrapped xStock address on Optimism.

This request swaps 0.1 ETH on Optimism into USDC in transaction 1, hands the USDC to an intent address, and buys `$XSTOCK_TOKEN` for `$ADDRESS` in transaction 2.

```bash theme={null}
curl --request POST \
  --url https://api.enso.build/api/v1/shortcuts/route \
  --header "Authorization: Bearer $ENSO_API_KEY" \
  --header 'Content-Type: application/json' \
  --data @- <<EOF
{
  "chainId": 10,
  "fromAddress": "$ADDRESS",
  "receiver": "$ADDRESS",
  "refundReceiver": "$ADDRESS",
  "routingStrategy": "router",
  "tokenIn": ["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"],
  "tokenOut": ["$XSTOCK_TOKEN"],
  "amountIn": ["100000000000000000"],
  "slippage": "100",
  "sameChainIntent": true
}
EOF
```

When `tokenIn` is already the settlement token (USDC on Optimism for xStocks, or USDT on BSC for Ondo GM), transaction 1 skips the swap and transfers `tokenIn` directly to the intent address.

The response, trimmed to the fields that matter here:

```json theme={null}
{
  "amountOut": "1234567890000000000",
  "minAmountOut": "1222222211100000000",
  "feeAmount": ["250000"],
  "ensoFeeAmount": ["125000"],
  "validUntil": 1764060180,
  "route": [
    {
      "action": "swap",
      "protocol": "enso",
      "tokenIn": ["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"],
      "tokenOut": ["0x0b2c639c533813f4aa9d7837caf62653d097ff85"],
      "chainId": 10
    },
    {
      "action": "route",
      "protocol": "enso",
      "tokenIn": ["0x0b2c639c533813f4aa9d7837caf62653d097ff85"],
      "tokenOut": ["0x..."],
      "chainId": 10
    }
  ],
  "intent": {
    "address": "0x...",
    "data": {
      "version": 1,
      "chainId": 10,
      "nonce": "123456789",
      "start": 1764060000,
      "deadline": 1764060300,
      "refundRecipient": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
      "triggers": [
        {
          "tokenType": 1,
          "data": "0x..."
        }
      ],
      "keeperFee": {
        "token": "0x0b2c639c533813f4aa9d7837caf62653d097ff85",
        "intentFee": "10000",
        "refundFee": "0"
      },
      "mode": 1,
      "payload": "0x..."
    }
  },
  "tx": {
    "to": "0x...",
    "from": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
    "data": "0x...",
    "value": "100000000000000000"
  },
  "metadata": {
    "bridgeFees": [],
    "bridgeRefundAssets": []
  }
}
```

Execute any required `preTransactions` first, then sign and submit `tx`. Save the transaction hash from `tx` to track execution.

## Response fields

| Field | Behavior on a same-chain intent |
| - | - |
| `intent` | Present only when a same-chain intent was built. Holds the one-time intent `address` and serialized intent `data`, including `deadline`, `refundRecipient`, `triggers`, and `keeperFee`. |
| `amountOut` | Expected `tokenOut` amount, net of route fees and the execution fee (`intent.data.keeperFee`). |
| `minAmountOut` | Minimum `tokenOut` enforced on transaction 2. |
| `validUntil` | Unix timestamp in seconds after which transaction 1 reverts on-chain. At most the 5-minute intent deadline minus a 2-minute execution buffer (3 minutes from quote time), or earlier if the swap quote in transaction 1 expires sooner. |
| `route` | Shows any source swap into the settlement token, followed by a single `enso` `route` hop representing transaction 2's buy of `tokenOut`. |
| `feeAmount` | Route fee amount in the settlement token's base units. Charged on transaction 2. |
| `ensoFeeAmount` | Enso platform fee amount in the settlement token's base units, when applicable under your fee policy. Charged on transaction 2. |
| `metadata.bridgeFees` | Empty (`[]`). There is no bridge. Read the execution fee from `intent.data.keeperFee`. |
| `metadata.bridgeRefundAssets` | Empty (`[]`). There is no bridge. |

## Track execution with `/intent/status`

Track a same-chain intent with `GET /api/v1/intent/status`, passing `chainId` and the hash of transaction 1 (`txHash`). Do not use `/api/v1/bridge/check` or `/api/v1/bridge/route`, which return `404` because there is no bridge.

```bash theme={null}
curl --get https://api.enso.build/api/v1/intent/status \
  --header "Authorization: Bearer $ENSO_API_KEY" \
  --data-urlencode 'chainId=10' \
  --data-urlencode "txHash=$TX_HASH"
```

Example response after transaction 2 executes:

```json theme={null}
{
  "chainId": 10,
  "txHash": "0xc314d333a270c60cf7f7dbd477cf60d3e5a9574fc4a3d80cd537f56963611784",
  "status": "delivered",
  "intent": {
    "requestId": "0x...",
    "executor": "0x...",
    "executionChainId": 10,
    "phase": "executed",
    "status": "executed",
    "source": "keeper",
    "deadline": "2026-11-25T10:05:00.000Z",
    "executionTxHash": "0x...",
    "executionExplorerUrl": "https://optimistic.etherscan.io/tx/0x...",
    "executedAt": "2026-11-25T10:00:18.000Z"
  }
}
```

### Status values

| Top-level `status` | `intent.phase` values | Meaning |
| - | - | - |
| `inflight` | `awaiting_funds`, `executing`, `refunding`, `unknown` | Not final yet. Keep polling. |
| `delivered` | `executed` | Transaction 2 executed and sent `tokenOut` to `receiver`. Read `intent.executionTxHash`. |
| `failed` | `refunded`, `failed` | The intent was refunded or given up. Check `intent.refundTxHash` and `intent.error`. |

In-flight status lookups refresh every 3 seconds, so polling every few seconds is sufficient.

### Error responses

| HTTP status | `error` field | Meaning |
| - | - | - |
| `400` | — | Malformed `chainId` or `txHash`, or an unsupported chain. |
| `404` | `TRANSACTION_NOT_FOUND` | Transaction 1 is not mined on `chainId` yet. Keep polling if you just submitted it. |
| `404` | `NO_INTENT` | Transaction 1 is mined, but it did not publish an intent from the chain's emitter. Stop polling. |

> [!NOTE]
>
> `GET /api/v1/intent/status` also accepts the source transaction hash of a cross-chain intent, but it reports only the intent execution stage. For cross-chain intents, continue using `GET /api/v1/bridge/route` to follow both the bridge and execution.

## Deadlines and refunds

* **Submission cutoff.** Transaction 1 enforces `block.timestamp <= validUntil` on-chain, where `validUntil` is at most 3 minutes after quoting (the 5-minute deadline minus a 2-minute execution buffer). Submitting transaction 1 late causes it to revert, so the user keeps `tokenIn`.
* **Intent expiry and refund.** Once transaction 1 succeeds, transaction 2 has until the 5-minute deadline (`intent.data.deadline`) to buy at least `minAmountOut` of `tokenOut`. If the buy does not complete in time, the settlement token (USDC for xStocks, USDT for Ondo GM on BSC) is refunded on `chainId` after the deadline.
* **Refund recipient.** Refunds go to `refundReceiver`, or to `receiver` when `refundReceiver` is omitted. `destinationBridgeRefundReceiver` is ignored on same-chain intents because there is no bridge.
* **No fees on refund.** Route fees are collected only when transaction 2 executes, so a refunded intent pays no `feeAmount` or `ensoFeeAmount`.

## Fees

* Transaction 1 charges no route or Enso platform fees.
* `feeAmount` (and `ensoFeeAmount`, when Enso's platform fee applies under your fee policy) are denominated in the **settlement token**, matching cross-chain intents, and are collected on transaction 2.
* `intent.data.keeperFee` reports the execution fee in the settlement token: `token` is the settlement token address, `intentFee` is the execution fee in base units, and `refundFee` is currently `"0"`.
* `amountOut` is net of route fees and `intent.data.keeperFee.intentFee`.
* `metadata.bridgeFees` is empty (`[]`).

## Fallback cases and errors

### Requests that fall back to the normal atomic route

The API silently returns a normal atomic route (without `intent` in the response) when any of the following apply:

* `sameChainIntent` is not `true`.
* `tokenOut` is not a supported mintable `xstocks`, `wrapped-xstocks`, or `ondo-gm` position with a single underlying token.
* `tokenIn` is itself an `xstocks`, `wrapped-xstocks`, or `ondo-gm` position.
* More than one `tokenIn` or `tokenOut` is passed.
* `amountIn` is a placeholder variable instead of a concrete amount.
* `slippage` is `"0"`.
* `minAmountOut` is set.
* `ignoreStandards` is non-empty.
* `allowAsync` is `true`.
* `swapType` is set to a value other than `"any"`.
* Same-chain intent execution is not enabled on `chainId`.

### Requests that return an error

These cases return an HTTP error instead of falling back:

| HTTP status | Cause |
| - | - |
| `400` | `sameChainIntent=true` is sent with `useIntentAddress=false`. |
| `400` | An eligible same-chain intent request omits `receiver`. |
| `400` | Your fee policy charges an Enso platform fee that cannot be collected on transaction 2 on `chainId`. |
| `400` | `amountIn` is too small to cover the execution fee or falls below the intent trigger amount. |
| `503` | Intent configuration is temporarily unavailable. |

Updated 2026-11-25


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