> For the complete documentation index, see [llms.txt](https://docs.zert.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zert.com/integration-example/full-swap-flow.md).

# Full swap flow

This guide walks through the public swap flow: quote, build, poll when needed, sign externally, submit the signed artifact, and optionally track the resulting transaction.

## Step 1: Request a quote

Call `POST /quote` with the source chain, destination chain, input token, output token, and amount.

## Step 2: Build the current signing step

Call `POST /swap/build` with the `quoteId` and selected `routeId`. Swagger does not auto-fill those fields from the Step 1 response, so paste the fresh values yourself when testing in the docs UI.

```bash
curl -X POST 'https://api.gateway.zert.com/api/v1/swap/build' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "quoteId": "REPLACE_WITH_QUOTE_ID_FROM_POST_QUOTE",
    "routeId": "REPLACE_WITH_ROUTE_ID_FROM_SELECTED_ROUTE",
    "recipient": "0x1234567890123456789012345678901234567890",
    "waitForTxRequestMs": 300
  }'
```

If you want retry-safe dedupe on direct HTTP calls, send your own `Idempotency-Key`. Swagger does not carry the prior quote response into this request. SDK and Postman flows can generate the idempotency key automatically, and Postman also captures the live `quoteId` and `routeId` for you.

The response is either:

* `mode: "sync"` with a ready-to-sign payload in `data.signing`
* `mode: "async"` with `pollAfterMs` telling you when to poll `GET /swap/{swapId}/signing`

If the signing surface for the active step is not configured, `POST /swap/build` returns `503` instead of a placeholder transaction.

Postman does not sign transactions. Hand the payload to the external wallet or signer you control.

## Step 3: Poll the signing endpoint

If the build response is async, poll until the signing payload is ready:

```bash
curl -X GET 'https://api.gateway.zert.com/api/v1/swap/your-swap-id/signing' \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

## Step 4: Submit the signed artifact

After the wallet signs the payload, submit the signed artifact:

```bash
curl -X POST 'https://api.gateway.zert.com/api/v1/swap/your-swap-id/signing' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "rawTx": "0x_signed_tx_from_external_wallet"
  }'
```

If the flow has multiple signing steps, keep polling the same endpoint until the next payload is ready.

## Step 5: Track the transaction

Once you have a transaction hash, use `GET /status/transaction/{txHash}?chainRef=...` to verify on-chain progress.

| Step | Endpoint                           | Purpose                         |
| ---- | ---------------------------------- | ------------------------------- |
| 1    | `POST /quote`                      | Request a quote                 |
| 2    | `POST /swap/build`                 | Build the current signing step  |
| 3    | `GET /swap/{swapId}/signing`       | Poll when signing is async      |
| 4    | `POST /swap/{swapId}/signing`      | Submit the signed artifact      |
| 5    | `GET /status/transaction/{txHash}` | Verify the on-chain transaction |

See [Request Quote](https://docs.zert.com/api-reference/swap/request-quote.md), [Build Swap](https://docs.zert.com/api-reference/swap/submit-swap.md), [Get Signing Status](https://docs.zert.com/api-reference/swap/get-wallet-signing-status.md), [Submit Signed Artifact](https://docs.zert.com/api-reference/swap/submit-wallet-signed-artifact.md), and [Get Transaction Status](https://docs.zert.com/api-reference/status-and-tracking/get-transaction-status.md) for full request and response details.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zert.com/integration-example/full-swap-flow.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
