# Build Swap Instructions

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

GET https://solana-mainnet.g.alchemy.com/v2/{apiKey}/swap/v2/build

Returns raw Solana swap instructions rather than a pre-built transaction.

Reference: https://www.alchemy.com/docs/chains/solana/solana-trader-api/build-swap-instructions

## Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| apiKey | string | Yes | For higher throughput, [create your own API key](https://dashboard.alchemy.com/signup). |

## Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| inputMint | string | Yes | Mint address of the input token. |
| outputMint | string | Yes | Mint address of the output token. |
| amount | string | Yes | Amount of the input token to swap, in its smallest unit (lamports for SOL, base units for SPL tokens).  |
| taker | string | Yes | Public key of the wallet that will sign the swap instructions. Required for `/build` since the instructions must reference concrete source and destination accounts.  |
| payer | string | No | Wallet that sponsors rent and account creation for `taker`. The taker still signs and pays the trade amount. To have this wallet also pay signature and priority fees, set it as the fee payer when you assemble the transaction. Any valid public key can be used; it has no effect when equal to `taker`.  |
| slippageBps | integer | No | Slippage tolerance in basis points, 0–10000. `rtse` (automatic slippage) is not supported.  |
| dexes | string | No | Comma-separated list of DEX labels to allow-list for routing (labels are case-sensitive). Mutually exclusive with `excludeDexes`.  |
| excludeDexes | string | No | Comma-separated list of DEX labels to exclude from routing (labels are case-sensitive). Mutually exclusive with `dexes`.  |
| platformFeeBps | integer | No | Integrator fee in basis points (0–10000). When greater than zero, `feeAccount` is required. Mutually exclusive with `referralFee` and `referralAccount`. |
| feeAccount | string | No | Token account that receives the integrator fee. Required when `platformFeeBps` is greater than zero. Only validated as a public key. Mutually exclusive with `referralFee` and `referralAccount`. |
| maxAccounts | integer | No | Maximum number of accounts the selected route may use, from 1 to 64. Lower values may restrict available routes. |
| wrapAndUnwrapSol | boolean | No | When `true`, Metis inserts wrap-SOL and unwrap-SOL instructions around the swap so native SOL can be used directly as input or output.  |
| destinationTokenAccount | string | No | Explicit destination SPL token account for the output tokens. Mutually exclusive with `nativeDestinationAccount`.  |
| nativeDestinationAccount | string | No | Explicit destination wallet for native SOL output. Mutually exclusive with `destinationTokenAccount`.  |
| blockhashSlotsToExpiry | integer | No | Number of slots the returned blockhash remains valid for, from 1 to 255. |
| tipAmount | integer | No | Not supported. |
| computeUnitPricePercentile | enum | No | Priority-fee level to target: `medium` (25th percentile), `high` (50th), or `veryHigh` (75th). If omitted, the 50th percentile is used. Numeric percentiles are not supported. The total priority fee is capped at 1,000,000 lamports. |
| mode | enum | No | Only `fast` is accepted; it currently has no effect on routing. |
| forJitoBundle | boolean | No | Set to `true` when quoting a swap intended for a Jito bundle. Forwarded to the routing engine. |
| referralFee | integer | No | Integrator fee in basis points (50–255). Must be sent with `referralAccount`. Mutually exclusive with `platformFeeBps` and `feeAccount`. |
| referralAccount | string | No | Referral account in the referral program. Must be sent with `referralFee`. The fee is charged in the output token and paid into that mint’s fee token account under this referral account. That token account must already exist. Mutually exclusive with `platformFeeBps` and `feeAccount`.  |

## Code Examples

### cURL

```bash
curl --request GET \
  --url 'https://solana-mainnet.g.alchemy.com/v2/docs-demo/swap/v2/build?inputMint=So11111111111111111111111111111111111111112&outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=1000000000&taker=GkwFnmMDvn3HGMpJpWBg8tgJxr3NxNvg3AXxvXVPbRGJ'
```

### JavaScript

```javascript
const options = {method: 'GET'};

fetch('https://solana-mainnet.g.alchemy.com/v2/docs-demo/swap/v2/build?inputMint=So11111111111111111111111111111111111111112&outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=1000000000&taker=GkwFnmMDvn3HGMpJpWBg8tgJxr3NxNvg3AXxvXVPbRGJ', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://solana-mainnet.g.alchemy.com/v2/docs-demo/swap/v2/build?inputMint=So11111111111111111111111111111111111111112&outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=1000000000&taker=GkwFnmMDvn3HGMpJpWBg8tgJxr3NxNvg3AXxvXVPbRGJ"

response = requests.get(url)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://solana-mainnet.g.alchemy.com/v2/docs-demo/swap/v2/build?inputMint=So11111111111111111111111111111111111111112&outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=1000000000&taker=GkwFnmMDvn3HGMpJpWBg8tgJxr3NxNvg3AXxvXVPbRGJ"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.get("https://solana-mainnet.g.alchemy.com/v2/docs-demo/swap/v2/build?inputMint=So11111111111111111111111111111111111111112&outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=1000000000&taker=GkwFnmMDvn3HGMpJpWBg8tgJxr3NxNvg3AXxvXVPbRGJ")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://solana-mainnet.g.alchemy.com/v2/docs-demo/swap/v2/build?inputMint=So11111111111111111111111111111111111111112&outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=1000000000&taker=GkwFnmMDvn3HGMpJpWBg8tgJxr3NxNvg3AXxvXVPbRGJ");
var client = new RestClient(options);
var request = new RestRequest("");
var response = await client.GetAsync(request);

Console.WriteLine("{0}", response.Content);

```


## Operation Specification

```yaml
path: /{apiKey}/swap/v2/build
method: GET
operation:
  summary: Build Swap Instructions
  description: Returns raw Solana swap instructions rather than a pre-built transaction.
  x-compute-units: 100
  x-rate-limit-cus: 60
  operationId: build-swap-instructions
  parameters:
    - name: apiKey
      in: path
      required: true
      schema:
        type: string
        default: docs-demo
      description: For higher throughput, [create your own API key](https://dashboard.alchemy.com/signup).
    - name: inputMint
      in: query
      required: true
      description: Mint address of the input token.
      schema:
        type: string
      example: So11111111111111111111111111111111111111112
    - name: outputMint
      in: query
      required: true
      description: Mint address of the output token.
      schema:
        type: string
      example: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
    - name: amount
      in: query
      required: true
      description: |
        Amount of the input token to swap, in its smallest unit (lamports for SOL, base units for SPL tokens).
      schema:
        type: string
      example: '1000000000'
    - name: taker
      in: query
      required: true
      description: |
        Public key of the wallet that will sign the swap instructions. Required for `/build` since the instructions must reference concrete source and destination accounts.
      schema:
        type: string
      example: GkwFnmMDvn3HGMpJpWBg8tgJxr3NxNvg3AXxvXVPbRGJ
    - name: payer
      in: query
      required: false
      description: |
        Wallet that sponsors rent and account creation for `taker`. The taker still signs and pays the trade amount. To have this wallet also pay signature and priority fees, set it as the fee payer when you assemble the transaction. Any valid public key can be used; it has no effect when equal to `taker`.
      schema:
        type: string
    - name: slippageBps
      in: query
      required: false
      description: |
        Slippage tolerance in basis points, 0–10000.

        `rtse` (automatic slippage) is not supported.
      schema:
        type: integer
        minimum: 0
        maximum: 10000
        default: 50
      example: 50
    - name: dexes
      in: query
      required: false
      description: |
        Comma-separated list of DEX labels to allow-list for routing (labels are case-sensitive). Mutually exclusive with `excludeDexes`.
      schema:
        type: string
    - name: excludeDexes
      in: query
      required: false
      description: |
        Comma-separated list of DEX labels to exclude from routing (labels are case-sensitive). Mutually exclusive with `dexes`.
      schema:
        type: string
    - name: platformFeeBps
      in: query
      required: false
      description: Integrator fee in basis points (0–10000). When greater than zero, `feeAccount` is required. Mutually exclusive with `referralFee` and `referralAccount`.
      schema:
        type: integer
        minimum: 0
        maximum: 10000
    - name: feeAccount
      in: query
      required: false
      description: Token account that receives the integrator fee. Required when `platformFeeBps` is greater than zero. Only validated as a public key. Mutually exclusive with `referralFee` and `referralAccount`.
      schema:
        type: string
    - name: maxAccounts
      in: query
      required: false
      description: Maximum number of accounts the selected route may use, from 1 to 64. Lower values may restrict available routes.
      schema:
        type: integer
        minimum: 1
        maximum: 64
    - name: wrapAndUnwrapSol
      in: query
      required: false
      description: |
        When `true`, Metis inserts wrap-SOL and unwrap-SOL instructions around the swap so native SOL can be used directly as input or output.
      schema:
        type: boolean
    - name: destinationTokenAccount
      in: query
      required: false
      description: |
        Explicit destination SPL token account for the output tokens. Mutually exclusive with `nativeDestinationAccount`.
      schema:
        type: string
    - name: nativeDestinationAccount
      in: query
      required: false
      description: |
        Explicit destination wallet for native SOL output. Mutually exclusive with `destinationTokenAccount`.
      schema:
        type: string
    - name: blockhashSlotsToExpiry
      in: query
      required: false
      description: Number of slots the returned blockhash remains valid for, from 1 to 255.
      schema:
        type: integer
        minimum: 1
        maximum: 255
    - name: tipAmount
      in: query
      required: false
      description: Not supported.
      schema:
        type: integer
        minimum: 1
    - name: computeUnitPricePercentile
      in: query
      required: false
      description: 'Priority-fee level to target: `medium` (25th percentile), `high` (50th), or `veryHigh` (75th). If omitted, the 50th percentile is used. Numeric percentiles are not supported. The total priority fee is capped at 1,000,000 lamports.'
      schema:
        type: string
        enum:
          - medium
          - high
          - veryHigh
    - name: mode
      in: query
      required: false
      description: Only `fast` is accepted; it currently has no effect on routing.
      schema:
        type: string
        enum:
          - fast
    - name: forJitoBundle
      in: query
      required: false
      description: Set to `true` when quoting a swap intended for a Jito bundle. Forwarded to the routing engine.
      schema:
        type: boolean
    - name: referralFee
      in: query
      required: false
      description: Integrator fee in basis points (50–255). Must be sent with `referralAccount`. Mutually exclusive with `platformFeeBps` and `feeAccount`.
      schema:
        type: integer
        minimum: 50
        maximum: 255
    - name: referralAccount
      in: query
      required: false
      description: |
        Referral account in the referral program. Must be sent with `referralFee`. The fee is charged in the output token and paid into that mint’s fee token account under this referral account. That token account must already exist. Mutually exclusive with `platformFeeBps` and `feeAccount`.
      schema:
        type: string
  responses:
    '200':
      description: Quote fields plus decomposed swap instructions.
      content:
        application/json:
          schema:
            type: object
            description: Quote fields plus decomposed swap instructions.
            properties:
              inputMint:
                type: string
                description: Mint of the input token, echoed back.
              outputMint:
                type: string
                description: Mint of the output token, echoed back.
              inAmount:
                type: string
                description: Input amount used for the quote, in base units of the input mint.
              outAmount:
                type: string
                description: |
                  Estimated output amount before slippage, in base units of the output mint.
              otherAmountThreshold:
                type: string
                description: |
                  Minimum output amount after slippage is applied, in base units of the output mint. `/build` is `ExactIn` only, so this is always a minimum output.
              swapMode:
                type: string
                description: |
                  Swap mode used to build the instructions. `/build` supports `ExactIn` only.
                enum:
                  - ExactIn
              slippageBps:
                type: integer
                description: Slippage tolerance in basis points applied to the quote.
              priceImpact:
                type: number
                description: |
                  Price impact of the swap, in percentage points (for example, `-0.1` means -0.1%). Same number as `/order`'s `priceImpact`. Always present.
              priceImpactPct:
                type: string
                description: |
                  Price impact as a decimal fraction string. `priceImpact` divided by 100. Always present.
              routePlan:
                type: array
                description: Ordered list of route steps that make up the swap.
                items:
                  type: object
                  properties:
                    swapInfo:
                      type: object
                      properties:
                        ammKey:
                          type: string
                          description: On-chain address of the AMM pool used for this step.
                        label:
                          type: string
                          description: Human-readable DEX label (for example, `Orca V2`, `Raydium CLMM`).
                        inputMint:
                          type: string
                        outputMint:
                          type: string
                        inAmount:
                          type: string
                        outAmount:
                          type: string
                      required:
                        - ammKey
                        - label
                        - inputMint
                        - outputMint
                        - inAmount
                        - outAmount
                    percent:
                      type: integer
                      description: Router-assigned percentage for this route step, from 0 to 100.
                      minimum: 0
                      maximum: 100
                    bps:
                      type: integer
                      description: Router-assigned share for this route step in basis points, from 0 to 10000.
                      minimum: 0
                      maximum: 10000
                    usdValue:
                      type: number
                      description: |
                        USD value of this step's input amount. Omitted when its input mint cannot be priced.
                  required:
                    - swapInfo
                    - percent
                    - bps
              setupInstructions:
                type: array
                description: |
                  Instructions that must run before the swap (for example, create an associated token account or wrap SOL). Always present; may be empty.
                items:
                  type: object
                  description: A Solana instruction in decomposed form.
                  properties:
                    programId:
                      type: string
                      description: ID of the program invoked by this instruction.
                    accounts:
                      type: array
                      items:
                        type: object
                        properties:
                          pubkey:
                            type: string
                          isSigner:
                            type: boolean
                          isWritable:
                            type: boolean
                        required:
                          - pubkey
                          - isSigner
                          - isWritable
                    data:
                      type: string
                      description: Base64-encoded instruction data.
                  required:
                    - programId
                    - accounts
                    - data
              swapInstruction:
                type: object
                description: A Solana instruction in decomposed form.
                properties:
                  programId:
                    type: string
                    description: ID of the program invoked by this instruction.
                  accounts:
                    type: array
                    items:
                      type: object
                      properties:
                        pubkey:
                          type: string
                        isSigner:
                          type: boolean
                        isWritable:
                          type: boolean
                      required:
                        - pubkey
                        - isSigner
                        - isWritable
                  data:
                    type: string
                    description: Base64-encoded instruction data.
                required:
                  - programId
                  - accounts
                  - data
              cleanupInstruction:
                description: |
                  Optional instruction that runs after the swap (for example, close a temporary wrapped-SOL account and reclaim rent). `null` when no cleanup is required.
                oneOf:
                  - type: object
                    description: A Solana instruction in decomposed form.
                    properties:
                      programId:
                        type: string
                        description: ID of the program invoked by this instruction.
                      accounts:
                        type: array
                        items:
                          type: object
                          properties:
                            pubkey:
                              type: string
                            isSigner:
                              type: boolean
                            isWritable:
                              type: boolean
                          required:
                            - pubkey
                            - isSigner
                            - isWritable
                      data:
                        type: string
                        description: Base64-encoded instruction data.
                    required:
                      - programId
                      - accounts
                      - data
                  - type: 'null'
              computeBudgetInstructions:
                type: array
                description: |
                  Compute-budget instructions for the caller's transaction. Contains exactly one `SetComputeUnitPrice` and no `SetComputeUnitLimit`; other compute-budget instruction types may be preserved. The price uses the requested priority-fee level, or the 50th percentile when omitted. A zero estimate is emitted as `SetComputeUnitPrice(0)`. The price is capped using an estimated fee ceiling of 1,000,000 lamports.
                items:
                  type: object
                  description: A Solana instruction in decomposed form.
                  properties:
                    programId:
                      type: string
                      description: ID of the program invoked by this instruction.
                    accounts:
                      type: array
                      items:
                        type: object
                        properties:
                          pubkey:
                            type: string
                          isSigner:
                            type: boolean
                          isWritable:
                            type: boolean
                        required:
                          - pubkey
                          - isSigner
                          - isWritable
                    data:
                      type: string
                      description: Base64-encoded instruction data.
                  required:
                    - programId
                    - accounts
                    - data
              otherInstructions:
                type: array
                description: |
                  Additional instructions Metis wants included in the final transaction (for example, integrator fee transfers). Always present; may be empty.
                items:
                  type: object
                  description: A Solana instruction in decomposed form.
                  properties:
                    programId:
                      type: string
                      description: ID of the program invoked by this instruction.
                    accounts:
                      type: array
                      items:
                        type: object
                        properties:
                          pubkey:
                            type: string
                          isSigner:
                            type: boolean
                          isWritable:
                            type: boolean
                        required:
                          - pubkey
                          - isSigner
                          - isWritable
                    data:
                      type: string
                      description: Base64-encoded instruction data.
                  required:
                    - programId
                    - accounts
                    - data
              tipInstruction:
                description: |
                  Reserved for a native tip. Always `null` on `/build` because `tipAmount` is not supported here (see the `tipAmount` parameter). If you need a Jito tip, use `/order`'s `jitoTipLamports` instead.
                oneOf:
                  - type: object
                    description: A Solana instruction in decomposed form.
                    properties:
                      programId:
                        type: string
                        description: ID of the program invoked by this instruction.
                      accounts:
                        type: array
                        items:
                          type: object
                          properties:
                            pubkey:
                              type: string
                            isSigner:
                              type: boolean
                            isWritable:
                              type: boolean
                          required:
                            - pubkey
                            - isSigner
                            - isWritable
                      data:
                        type: string
                        description: Base64-encoded instruction data.
                    required:
                      - programId
                      - accounts
                      - data
                  - type: 'null'
              addressesByLookupTableAddress:
                type:
                  - object
                  - 'null'
                description: |
                  Address lookup table accounts referenced by the swap, keyed by lookup-table address. Each value is the ordered list of accounts resolved from that table. `null` when the route uses no lookup tables. Never an empty object.
                additionalProperties:
                  type: array
                  items:
                    type: string
              blockhashWithMetadata:
                type: object
                description: |
                  Recent blockhash Metis fetched for the swap transaction, plus its expiry and the timestamp this service stamped when building the response.
                properties:
                  blockhash:
                    type: array
                    description: |
                      Blockhash as an array of 32 unsigned bytes. It is not base58-encoded.
                    minItems: 32
                    maxItems: 32
                    items:
                      type: integer
                      minimum: 0
                      maximum: 255
                  lastValidBlockHeight:
                    type: integer
                    description: |
                      Block height beyond which the blockhash is no longer valid, as a JSON number. (On `/order`'s top-level response the equivalent `lastValidBlockHeight` is a decimal string; on `/build` here it is a number.)
                  fetchedAt:
                    type: object
                    description: |
                      Timestamp this service stamps when building the response. Keys are snake_case as returned.
                    properties:
                      secs_since_epoch:
                        type: integer
                        description: Seconds since Unix epoch.
                      nanos_since_epoch:
                        type: integer
                        description: Nanoseconds portion of the timestamp.
                    required:
                      - secs_since_epoch
                      - nanos_since_epoch
                required:
                  - blockhash
                  - lastValidBlockHeight
                  - fetchedAt
            required:
              - inputMint
              - outputMint
              - inAmount
              - outAmount
              - otherAmountThreshold
              - swapMode
              - slippageBps
              - priceImpact
              - priceImpactPct
              - routePlan
              - setupInstructions
              - swapInstruction
              - cleanupInstruction
              - computeBudgetInstructions
              - otherInstructions
              - tipInstruction
              - addressesByLookupTableAddress
              - blockhashWithMetadata
          example:
            inputMint: So11111111111111111111111111111111111111112
            outputMint: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
            inAmount: '1000000000'
            outAmount: '234506710'
            otherAmountThreshold: '233333336'
            swapMode: ExactIn
            slippageBps: 50
            priceImpact: -0.05
            priceImpactPct: '-0.0005'
            routePlan:
              - swapInfo:
                  ammKey: 5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1
                  label: Orca V2
                  inputMint: So11111111111111111111111111111111111111112
                  outputMint: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
                  inAmount: '1000000000'
                  outAmount: '234506710'
                percent: 100
                bps: 10000
                usdValue: 234.3
            setupInstructions: []
            swapInstruction:
              programId: JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4
              accounts:
                - pubkey: GkwFnmMDvn3HGMpJpWBg8tgJxr3NxNvg3AXxvXVPbRGJ
                  isSigner: true
                  isWritable: true
              data: AQAAAA...
            cleanupInstruction: null
            computeBudgetInstructions:
              - programId: ComputeBudget111111111111111111111111111111
                accounts: []
                data: AgAAAA==
            otherInstructions: []
            tipInstruction: null
            addressesByLookupTableAddress:
              AddrLookupTab1e1111111111111111111111111111:
                - EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
                - So11111111111111111111111111111111111111112
            blockhashWithMetadata:
              blockhash:
                - 12
                - 34
                - 56
                - 78
                - 90
                - 12
                - 34
                - 56
                - 78
                - 90
                - 12
                - 34
                - 56
                - 78
                - 90
                - 12
                - 34
                - 56
                - 78
                - 90
                - 12
                - 34
                - 56
                - 78
                - 90
                - 12
                - 34
                - 56
                - 78
                - 90
                - 12
                - 34
              lastValidBlockHeight: 300000000
              fetchedAt:
                secs_since_epoch: 1750000000
                nanos_since_epoch: 0
```
