> 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

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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.zert.com/routing-engine-sdk/submit-a-swap.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
