POST /swap

POST /swap | Auth: Required

Build an unsigned swap transaction. The response contains raw transaction data that the caller must sign and submit to the blockchain. This endpoint does not execute the swap -- it only prepares the transaction.

For server-side signing with managed wallets, use POST /swap/execute instead (not covered in this reference).

Request

Body

There are two usage modes:

Mode 1: Using a quote (recommended)

Field
Type
Required
Description

quote_id

string

Yes

Quote ID from POST /quote. Must not be expired (60s TTL).

wallet_address

string

Yes

Address that will sign and submit the transaction.

Mode 2: Direct swap (no quote)

Field
Type
Required
Description

wallet_address

string

Yes

Address that will sign and submit the transaction.

from_token

string

Yes

Source token symbol.

to_token

string

Yes

Destination token symbol.

amount

string

Yes

Human-readable amount to swap.

chain

string

No

Chain key. Defaults to "ethereum".

slippage

number

No

Max slippage as a decimal (0-1). Default: 0.03.

Example (With Quote)

Example (Direct)

Response

Status: 200 OK

Fields

Field
Type
Description

success

boolean

Always true.

transaction.to

string

Contract address to send the transaction to.

transaction.data

string

Hex-encoded calldata.

transaction.value

string

Native token value in wei (hex-encoded). "0x0" for ERC-20 to ERC-20 swaps.

transaction.gas_estimate

string

Estimated gas limit (hex-encoded).

transaction.chain_id

number

Chain ID for the transaction.

meta.from_token

string

Source token symbol.

meta.to_token

string

Destination token symbol.

meta.amount_in

string

Human-readable input amount.

meta.expected_out

string

Human-readable expected output amount.

meta.min_out

string

Minimum output after slippage.

Example

Important: The response contains an unsigned transaction. You must sign it with the private key of wallet_address and broadcast it to the chain yourself.

Errors

Status
Error
Description

400

"wallet_address is required"

Missing required field.

400

"Provide quote_id or (from_token, to_token, amount)"

Neither a quote ID nor direct swap parameters were provided.

400

"Quote has expired"

The quote_id is older than 60 seconds. Request a new quote.

400

"Invalid quote_id"

The quote_id does not exist.

400

"Insufficient liquidity for this trade"

The swap cannot be completed at the requested size.

400

"Unknown token 'XYZ' on chain 'base'"

Token not supported on the specified chain.

401

"Invalid or missing API key"

The API key is missing, malformed, or revoked.

Code Examples

curl

Python

TypeScript

Last updated