# Migrate to v3

> Map each v2 endpoint, field and state to v3, and move an integration over without losing track of open orders.

> API v2 is deprecated. It stays supported, but new integrations should use the [Khalani API](/) (v3). See [Migrate to v3](/v2/migrate/).

v3 works on the same orders, settlement and contracts as v2, with the same API key, terms and order deadline. What changes is the shape of the API: chain-neutral ids, quote options instead of a build object, funding steps instead of transactions, one error shape, and order creation that is safe to retry.

Read these v3 pages first: the [Quickstart](/quickstart/), [Conventions](/guides/conventions/), [Create orders](/guides/create-orders/) and [Fund orders](/guides/fund-orders/). Every v3 field is in the [API reference](/api/).

## Move over gradually

1. Create new orders through v3.
2. Keep tracking orders you built through v2 with v3: `GET /v3/orders/{id}` takes their `0x` order id, and `GET /v3/orders` lists them. You can also keep reading them through v2 until they are done.
3. Retire your v2 calls once no v2-built order is open.

## Endpoint mapping

| v2 | v3 | What changes |
|---|---|---|
| `GET /v2/params` | `GET /v3/catalog` | Chains and assets are CAIP ids. Fees are per asset as before. Your `orderTtl` and commission wallet aren't listed: each quote gives the deadlines as `terms.fundWithinSeconds` and `terms.fillWithinSeconds`. |
| `GET /v2/quote?fromChainId=…&from=…&toChainId=…&to=…&srcAmount=…` | `POST /v3/quote` with `{ send: { asset, amount }, receive: { asset } }` | A JSON body. The answer is a list of options instead of one `build` object. |
| `POST /v2/build` | `POST /v3/orders` with `{ option, accounts }` | Send the option's `id` instead of the `build` object. Repeating the request returns the same order instead of creating another. The answer is the whole order, with its funding steps. |
| `GET /v2/orders/{orderId}` (no key) | `GET /v3/orders/{id}` (key) | Takes the `ord_` id or the `0x` id. Needs your key. |
| `GET /v2/orders` | `GET /v3/orders` | Filters by `status`, `account`, `sendAsset` and `receiveAsset`. `sort=updatedAt` syncs every changed order. Pages of up to 50. |
| `POST /v2/orders/{orderId}/cancel` | `POST /v3/orders/{id}/actions` with `{ kind: "cancel", signature }` | `refundTo` signs a plain message with `personal_sign`, instead of the depositor signing EIP-712 typed data with a nonce. On orders created through v3, TRON, Stellar and EIP-1271 contract wallets can cancel. A v2-built order keeps its v2 rule: one with a TRON, Stellar or Solana asset can't be cancelled early. |
| `GET /v2/health` | None | Use `GET /v3/catalog` as your readiness check. |
| None | `GET /v3/orders/{id}/changes` | New: an order's history. |

## Quote and build fields

| v2 | v3 |
|---|---|
| `fromChainId` + `from`, `toChainId` + `to` | `send.asset`, `receive.asset`: CAIP-19 ids from the catalog |
| `srcAmount` | `send.amount` |
| `spend.amount` | `display.send` |
| `receive.amount`, `receive.minAmount` | `display.receive`, `display.receiveMin` |
| `details.protocolFee` | `display.protocolFee`. The flat fee alone is `display.flatFee`. |
| `slippageBps` | `terms.slippageBps`, with the rate it gives in `terms.minRate` |
| `earlyCancelDisabled` | `actions.cancel.available` on the option |
| `build`, `build.terms` | The option's `id`. It carries the signed terms, so there is nothing else to send back. |
| `depositor` | `accounts.payer` |
| `payoutAddr` | `accounts.recipient`, now always required |
| `refundAddr` | `accounts.refundTo` |
| `400` with `detail.minSrcAmount`, `409` with `detail.maxSrcAmount` | `422 AMOUNT_TOO_SMALL` or `AMOUNT_TOO_LARGE`, with the range in `details.minAmount` and `details.maxAmount` |

## Build response to funding steps

| v2 | v3 |
|---|---|
| `orderId` | `id` (`ord_…`). The `0x` id is `protocolId`. |
| `approveTxs[]` | The `approve_reset` and `approve` steps. Check the allowance yourself first: see [Fund orders](/guides/fund-orders/#check-the-allowance-first). |
| `depositTx` | The `deposit` step's `instruction.payload`. `value` and `gasLimit` are decimal strings, where v2 sent hex. |
| `depositAddress`, `expectedAmount` | The `transfer` step's `instruction.to` and `instruction.amount` |
| `deadline`, or build time plus `orderTtl` | `terms.fundBy` to send the deposit by, and `terms.fillBy` for the order |

## States to statuses

| v2 `state` | v3 `status` |
|---|---|
| `pending_deposit` | `awaiting_funding`, or `expired` once `fillBy` passes unpublished |
| `deposited` | `confirming`, or `expired` once `fillBy` passes unpublished |
| `published`, `partially_filled` | `trading` |
| `terminal_chain` | `settling` |
| `withdrawn_on_hub`, `delivery_failed` | `delivering`. A failed delivery shows the `DELIVERY_STUCK` notice. |
| `delivered` | `done` |

Stop routine polling when `summary.pollAfterSeconds` is null, where v2 stopped at `delivered` or `delivery_failed`. Keep syncing with `GET /v3/orders?sort=updatedAt` to receive later refunds: an `expired` order can become `delivering` or `done`.

## Order fields

| v2 | v3 |
|---|---|
| `traces.withdraw.settledOutcome` | `summary.payout.amount` |
| `traces.withdraw.refundSource` | `summary.refund.amount` |
| `deliver.payout`, `deliver.refund` | `summary.payout`, `summary.refund`, with `status` and `tx` |
| `deliveryFailed` | `summary.notices`, `DELIVERY_STUCK` |
| `traces.withdraw.accruedFee` | `charges.protocolFee` |
| `traces.rootIntentId` | Not needed: the cancel message comes from `actions.cancel.proof.message`. |
| `traces.chainObservations` | `fills`, with what each fill used and paid, and `GET /v3/orders/{id}/changes` |

## Errors

v2 has four error body shapes. v3 has one, `ApiError`, with a `code` and a `recovery` that tells you what to do next. Handle errors by `recovery`. See [Errors and retries](/guides/errors/).

## Retries

`POST /v2/build` creates a new order on every success, so a v2 integration must never retry one that returned. `POST /v3/orders` is safe to repeat: the same option and accounts always return the same order. Drop any v2 workaround that looked an order up after a lost build response.
