Swap

Create Swap Instructions

Returns Solana swap instructions for a given token pair and amount.

post/swap-instructions

Headers

0x-api-keystring required

Visit dashboard.0x.org to get your API Key

Request body

amount_ininteger required

Input amount in its base units.

disabled_sourcesstring[]

DEX sources to exclude from routing. Valid source names are returned by /enabled-sources.

reserve_transaction_bytesinteger

Minimum bytes to reserve in the transaction for composing with additional instructions.

slippage_bpsinteger

Slippage tolerance in basis points.

sponsorstring

Transaction fee payer and rent payer for a fully-sponsored swap. Must differ from the taker and from every native destination in the request. The taker remains the swap authority and must still sign.

swap_fee_ppmstring

Comma-separated volume-based swap fees in parts per million. Must be provided together with swap_fee_recipient. Each entry must be between 0 and the per-app maximum (100_000 unless configured otherwise). A value of 0 disables that fee entry. Multiple fees on the same side are applied sequentially, each on the amount remaining after prior deductions — not the original amount. Fee amounts are rounded up to the nearest base unit.

swap_fee_sidestring

Comma-separated fee sides for each fee entry. Supported values are buy and sell. This field may be omitted only when every fee uses the default buy side. When provided, the number of entries must match swap_fee_ppm.

takerstring required

Base-58 encoded taker wallet address.

token_instring required

Input token mint, base-58 encoded. Use So11111111111111111111111111111111111111111 for native SOL.

token_outstring required

Output token mint, base-58 encoded. Use So11111111111111111111111111111111111111111 for native SOL.

trade_surplus_cap_ppminteger

Trade surplus cap in parts per million of the total realized trade size. Must be provided together with trade_surplus_recipient, or both fields must be omitted. A value of 0 disables trade surplus collection for the request. When 0x controls trade surplus collection, the request value is ignored and the configured 0x policy is applied instead. The transferred amount is capped relative to trade size.

Example request

{
  "amount_in": 1000000000,
  "slippage_bps": 50,
  "taker": "ZeroEx1111111111111111111111111111111111111",
  "token_in": "So11111111111111111111111111111111111111112",
  "token_out": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
}

Response

Swap instructions

address_lookup_tablesstring[] required

Address Lookup Table addresses that must be included in the versioned transaction.

amount_outinteger required

The estimated output amount after fees, in its base units.

min_amount_outinteger required

The minimum output amount after slippage and fees, in its base units. Transaction will fail if this amount is not met.

sponsorstring

Present when the caller requested full sponsorship. The returned transaction must use this address as fee payer; both sponsor and taker sign.

zidstring required

Unique 12-byte hex identifier for this request.

Changes