> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pods.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Execute Swap

> Learn how to generate bytecode and execute a token swap using a quote

In this section, you'll learn how to execute a token swap using the transaction data generated from a previously obtained quote.

<Info>
  **Prerequisites:** Complete the [Get a Quote](/guides/swaps/get-quote) guide first to obtain a valid quote.
</Info>

## Overview

After obtaining a quote, you can execute the swap by generating the necessary transaction data (bytecode) and submitting it to the blockchain. The Pods API handles the complexity of preparing the transaction data for different providers and swap types.

<Tip>
  **One-call flow:** If you pass both `originAddress` and `destinationAddress` to `GET /v2/swap/quote`, the response already includes `id`, `chainId`, and `transactionData` alongside `quote` — you can skip `POST /v2/swap/bytecode` entirely and go straight to signing the returned transactions.
</Tip>

<Warning>
  **Trustless Operation:** You sign and submit all transactions yourself. Pods never has custody of your funds.
</Warning>

## Executing a Swap

### Endpoint

```http theme={null}
POST /v2/swap/bytecode
```

### Request Body

| Parameter            | Type   | Required | Description                                                                                                                                                  |
| -------------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `quoteId`            | string | ✅        | The quote ID returned by `GET /v2/swap/quote`                                                                                                                |
| `originAddress`      | string | ✅        | The wallet address that will sign and send the transaction                                                                                                   |
| `destinationAddress` | string | ✅        | The destination wallet address to receive the swapped tokens. For cross-chain swaps, this address is used as the `receiverAddress` on the destination chain. |
| `rawQuote`           | any    | Optional | Provider-specific quote data from the quote response. Only present for certain bridge providers; pass it when the quote response includes it.                |
| `output`             | string | Optional | Response format: `bytecode` (default), `userOperation` (ERC-4337), or `fireblocks` (Fireblocks contract call).                                               |
| `accountId`          | number | Optional | Fireblocks vault account ID. Required when `output` is `fireblocks`.                                                                                         |

### Example Request

```bash theme={null}
curl --request POST \
  --url https://api.pods.finance/v2/swap/bytecode \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: YOUR_API_KEY' \
  --data '{
    "quoteId": "550e8400-e29b-41d4-a716-446655440000",
    "originAddress": "0x1234567890123456789012345678901234567890",
    "destinationAddress": "0x1234567890123456789012345678901234567890",
    "rawQuote": "..."
  }'
```

## Response Format

The API returns transaction data ready to be signed and executed:

```json theme={null}
{
  "id": "65f1a2b3c4d5e6f789012345",
  "chainId": 137,
  "transactionData": [
    {
      "to": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
      "data": "0x095ea7b3000000000000000000000000111111125421ca6dc452d289314280a0f8842a6500000000000000000000000000000000000000000000000000000000000f4240",
      "value": "0",
      "chainId": 137
    },
    {
      "to": "0x111111125421ca6dc452d289314280a0f8842a65",
      "data": "0x07ed2379...",
      "value": "0",
      "chainId": 137
    }
  ]
}
```

## Response Fields

<AccordionGroup>
  <Accordion title="id" icon="fingerprint">
    ID created for execution tracking. Use this ID with `GET /actions/{id}` when you need execution status after transactions are submitted.
  </Accordion>

  <Accordion title="chainId" icon="link">
    The chain ID where these transactions should be executed
  </Accordion>

  <Accordion title="transactionData" icon="list">
    EVM routes return an array of transaction legs when `output=bytecode` (default). **Batch all legs
    on the same `chainId` into one atomic transaction** — see
    [Executing Bytecode](/getting-started/executing-bytecode). Solana routes return provider-specific
    transaction data with a `rawTransaction` payload. When `output=fireblocks`, returns a Fireblocks
    contract call payload instead of a transaction array. Typical EVM legs:

    * **Approval**: Grants permission to the swap contract
    * **Swap**: Executes the actual token swap
    * **Tracking**: Records the swap in Pods's system
  </Accordion>

  <Accordion title="userOperation" icon="bolt">
    ERC-4337 user operation object. Only present when `output=userOperation` is requested.
  </Accordion>

  <Accordion title="to" icon="paper-plane">
    The contract address to send the transaction to
  </Accordion>

  <Accordion title="data" icon="code">
    Encoded transaction data (bytecode) for the contract call
  </Accordion>

  <Accordion title="value" icon="coins">
    Amount of native token to send (in wei). Usually "0" unless swapping native tokens.
  </Accordion>
</AccordionGroup>

<Info>
  `quoteId` and `id` identify different resources. `quoteId` tracks the saved swap quote and is the `{id}` for `GET /v2/swap/status/{id}`. The `id` returned by this endpoint is used for execution tracking.
</Info>

## Transaction Execution

Sign and submit the transaction data on your end — Pods never has custody of your funds.

<Warning>
  **Execute atomically.** Do not send each item in `transactionData` as a separate transaction.
  Batch all same-chain legs into one tx (EIP-7702, smart-account userOp, or Fireblocks batch).
  See [Executing Bytecode](/getting-started/executing-bytecode).
</Warning>

| Your stack                  | `output`                   | Guide                                                                   |
| --------------------------- | -------------------------- | ----------------------------------------------------------------------- |
| EOA (MetaMask, wagmi, viem) | `bytecode`                 | [EIP-7702](/examples/javascript/using-eip7702)                          |
| ERC-4337 smart account      | `userOperation`            | [Smart Account Deposit](/examples/javascript/smart-account-deposit)     |
| Fireblocks custody          | `fireblocks` + `accountId` | [Fireblocks Integration](/external-integrations/fireblocks-integration) |

### EOA — EIP-7702 (recommended)

Use [EIP-7702 `executeBatch`](/examples/javascript/using-eip7702) to encode all
`transactionData` legs into a single type-4 transaction. Map `transactionData` the same way as
`bytecode` in the strategy examples.

### Smart account — `output=userOperation`

Request `output=userOperation` on `POST /v2/swap/bytecode` (or inline on the quote when both
addresses are set). Submit the returned `userOperation` through your bundler — one userOp, not a
loop of separate sends.

### Fireblocks — `output=fireblocks`

Pass `accountId` and submit `transactionData` to the Fireblocks Transactions API. See
[Fireblocks Integration](/external-integrations/fireblocks-integration).

## Swap Types

The endpoint automatically handles different swap types:

<Tabs>
  <Tab title="Same-Chain">
    **Same-chain swaps** (e.g., USDT to USDC on Ethereum):

    * Usually 2-3 transactions: approve + swap (+ tracking)
    * Executes immediately on the same blockchain
    * Lower fees, faster execution
  </Tab>

  <Tab title="Cross-Chain">
    **Cross-chain swaps** (e.g., USDT on Ethereum to USDC on Polygon):

    * Involves bridge operations
    * May take several minutes to complete
    * Webhooks notify you of status changes
    * Use `/v2/swap/status/{quoteId}` for quote status and `GET /actions/{id}` for execution status
  </Tab>
</Tabs>

## Error Handling

The API returns appropriate error messages for:

* Missing required parameters
* Invalid or expired quote
* Quote not found or already used
* Provider-specific errors during transaction preparation

**Example Error Response:**

```json theme={null}
{
  "error": {
    "code": "QUOTE_NOT_FOUND",
    "message": "Quote not found or expired"
  }
}
```

<Warning>
  Always check that the quote hasn't expired before executing. Quotes are typically valid for 5 minutes.
</Warning>

## Complete Workflow

<Steps>
  <Step title="Get Quote">
    Use `GET /v2/swap/quote` to get swap quote and pricing
  </Step>

  <Step title="Generate Bytecode">
    Use `POST /v2/swap/bytecode` with the quote to generate transaction data. Save the returned `id`.
  </Step>

  <Step title="Execute Transactions">
    Sign and send the transactions using your wallet
  </Step>

  <Step title="Track Status">
    For cross-chain swaps, use `GET /v2/swap/status/{quoteId}` to monitor quote progress.

    Pass the `quoteId` returned in step 1 as the `{quoteId}` path parameter. Use the `id` returned in step 2 with `GET /actions/{id}` when you need execution status.
  </Step>
</Steps>

## Next Steps

<CardGroup cols={2}>
  <Card title="Get Another Quote" icon="rotate" href="/guides/swaps/get-quote">
    Start a new swap
  </Card>

  <Card title="Check Status" icon="magnifying-glass" href="/api-reference">
    Track cross-chain swap progress
  </Card>

  <Card title="Code Examples" icon="code" href="/examples/javascript/same-chain-swap">
    View complete implementation examples
  </Card>
</CardGroup>
