Skip to content
Alchemy Logo

Build Swap Instructions

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

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

Path Parameters

stringrequireddefaults to docs-demo

For higher throughput, create your own API key.

Query Parameters

stringrequired

Mint address of the input token.

stringrequired

Mint address of the output token.

stringrequired

Amount of the input token to swap, in its smallest unit (lamports for SOL, base units for SPL tokens).

stringrequired

Public key of the wallet that will sign the swap instructions. Required for /build since the instructions must reference concrete source and destination accounts.

stringoptional

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.

integeroptionaldefaults to 50

Slippage tolerance in basis points, 0–10000.

rtse (automatic slippage) is not supported.

stringoptional

Comma-separated list of DEX labels to allow-list for routing (labels are case-sensitive). Mutually exclusive with excludeDexes.

stringoptional

Comma-separated list of DEX labels to exclude from routing (labels are case-sensitive). Mutually exclusive with dexes.

integeroptional

Integrator fee in basis points (0–10000). When greater than zero, feeAccount is required. Mutually exclusive with referralFee and referralAccount.

stringoptional

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.

integeroptional

Maximum number of accounts the selected route may use, from 1 to 64. Lower values may restrict available routes.

booleanoptional

When true, Metis inserts wrap-SOL and unwrap-SOL instructions around the swap so native SOL can be used directly as input or output.

stringoptional

Explicit destination SPL token account for the output tokens. Mutually exclusive with nativeDestinationAccount.

stringoptional

Explicit destination wallet for native SOL output. Mutually exclusive with destinationTokenAccount.

integeroptional

Number of slots the returned blockhash remains valid for, from 1 to 255.

integeroptional

Not supported.

enumoptional

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.

Allowed values:

enumoptional

Only fast is accepted; it currently has no effect on routing.

Allowed values:

booleanoptional

Set to true when quoting a swap intended for a Jito bundle. Forwarded to the routing engine.

integeroptional

Integrator fee in basis points (50–255). Must be sent with referralAccount. Mutually exclusive with platformFeeBps and feeAccount.

stringoptional

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.

Responses

200

Quote fields plus decomposed swap instructions.

Was this page helpful?