Create Swap Instructions

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

Headers

0x-api-keystringRequired
Visit dashboard.0x.org to get your API Key

Request

This endpoint expects an object.
amount_inlongRequired>=1
Input amount in its base units.
takerstringRequired

Base-58 encoded taker wallet address.

token_instringRequired

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

token_outstringRequired

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

disabled_sourceslist of stringsOptional

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

recipientstring or object or nullOptional

A swap destination: either an existing token account (or wallet for native SOL) address, or an owner whose token account should be used, and created if required. If an account is created, its rent is paid by sponsor if present, else by taker. If the created ATA belongs to the taker, the sponsor keeps close authority and can reclaim the rent once the account is empty. ATAs created for anyone else (custom recipient, fee or surplus recipient) leave the rent as a permanent sponsor cost.

reserve_transaction_byteslongOptional>=0Defaults to 0
Minimum bytes to reserve in the transaction for composing with additional instructions.
slippage_bpsintegerOptional0-10000Defaults to 50
Slippage tolerance in basis points.
sponsorstringOptional

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_ppmstringOptional

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_recipientstring or list of strings or objects or nullOptional

Fee recipients for the swap fees: either a comma-separated list of existing token accounts, or a structured list mixing addresses with owners whose token accounts should be the fee recipient.

swap_fee_sidestringOptional

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.

trade_surplus_cap_ppmintegerOptional0-1000000

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.

trade_surplus_recipientstring or object or nullOptional

A swap destination: either an existing token account (or wallet for native SOL) address, or an owner whose token account should be used, and created if required. If an account is created, its rent is paid by sponsor if present, else by taker. If the created ATA belongs to the taker, the sponsor keeps close authority and can reclaim the rent once the account is empty. ATAs created for anyone else (custom recipient, fee or surplus recipient) leave the rent as a permanent sponsor cost.

Response

Swap instructions
address_lookup_tableslist of strings
Address Lookup Table addresses that must be included in the versioned transaction.
amount_outlong>=0
The estimated output amount after fees, in its base units.
instructionslist of objects
The instructions to perform the swap.
min_amount_outlong>=0
The minimum output amount after slippage and fees, in its base units. Transaction will fail if this amount is not met.
route_planlist of objects
List of swap legs comprising the swap.
zidstring

Unique 12-byte hex identifier for this request.

sponsorstringOptional

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

Errors

4XX
Client Request Error
5XX
Server Error