> 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/routing-engine-sdk/submit-a-swap.md).

# Submit a Swap

Build and execute the public swap flow: Build -> Get signing -> Submit signed artifact.

Use this flow after `POST /quote`. The SDK exposes these methods:

* Layer-based: `sdk.swap.build`, `sdk.swap.getSigning`, `sdk.swap.submitSigning`
* Flat: `sdk.buildSwap`, `sdk.getSwapSigning`, `sdk.submitSwapSigning`

***

### Build swap

#### `build`

Calls `POST /swap/build`.

**Parameters**

* `body` (SwapBuildRequest, required)
  * `quoteId` (string, required)
  * `routeId` (string, required)
  * `recipient` (string, required)
  * `waitForTxRequestMs` (number, optional)

**Returns**

A Promise that resolves to `SwapBuildResponse`.

* `data.swapId` (string)
* `data.mode` (`"sync"` or `"async"`)
* `data.nextAction` (`"sign"` or `"poll"`)
* `data.pollAfterMs` (number, optional)
* `data.signing` (signing payload + hints)
* `meta.requestId` (string): Request identifier.
* `meta.timestamp` (string): Response timestamp.

***

### Get signing status

#### `getSigning`

Calls `GET /swap/{swapId}/signing`.

**Parameters**

* `swapId` (string, required)

**Returns**

A Promise that resolves to `SwapSigningResponse` with the same top-level shape as build (`swapId`, `mode`, `nextAction`, `pollAfterMs`, `signing`).

***

### Submit signed artifact

#### `submitSigning`

Calls `POST /swap/{swapId}/signing`.

**Parameters**

* `swapId` (string, required)
* `body` (SwapSubmitSigningRequest, required)
  * `rawTx` (string, required): Signed transaction artifact.

**Returns**

A Promise that resolves to `SwapSigningResponse` (typically `nextAction: "poll"` while next step is preparing).

```typescript
import { RoutingEngineSDK } from 'routing-engine-sdk';

const sdk = new RoutingEngineSDK({
  api: { apiKey: 'your-api-key' },
});

try {
  const quote = await sdk.quote.request({
    fromChain: 'arbitrum',
    toChain: 'avax',
    tokenIn: 'TBTC',
    tokenOut: 'WETH',
    network: 'mainnet',
    amount: '100.00',
    slippageBps: 75,
    recipient: '0x1234567890123456789012345678901234567890',
  });

  const build = await sdk.swap.build({
    quoteId: quote.data.quoteId,
    routeId: quote.data.routes[0].routeId,
    recipient: '0x1234567890123456789012345678901234567890',
  });

  const signing = await sdk.swap.getSigning(build.data.swapId);
  if (signing.data.nextAction === 'sign') {
    // Sign with wallet/signer, then submit the signed raw transaction.
    await sdk.swap.submitSigning(build.data.swapId, { rawTx: '0xsigned_raw_tx' });
  }
} catch (error) {
  console.error(error);
}
```


---

# 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/routing-engine-sdk/submit-a-swap.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.
