Skip to main content
POST
/
defi
/
swaps
/
prepare
Prepare swap transaction
curl --request POST \
  --url http://localhost:4000/v1/defi/swaps/prepare \
  --header 'Authorization: <api-key>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "userAddress": "0xb322E239E5A32724633A595b8f8657F9cbb307B2",
  "tokenIn": "0x0000000000000000000000000000000000000000",
  "tokenOut": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
  "amountIn": "1000000000000000000",
  "amountOutMinimum": "1450000000",
  "chainId": 1
}
'
{
  "success": true,
  "serializedTransaction": "<string>",
  "gasEstimation": {},
  "expectedAmountOut": "1500000000",
  "message": "Swap transaction prepared successfully",
  "approvalTransaction": "<string>"
}

Authorizations

Authorization
string
header
required

Use this format: ApiKey <your_api_key>

Body

application/json
userAddress
string
required

User wallet address

Example:

"0xb322E239E5A32724633A595b8f8657F9cbb307B2"

tokenIn
string
required

Input token address (use 0x0000000000000000000000000000000000000000 for native token)

Example:

"0x0000000000000000000000000000000000000000"

tokenOut
string
required

Output token address

Example:

"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"

amountIn
string
required

Amount to swap (in token decimals)

Example:

"1000000000000000000"

amountOutMinimum
string
required

Minimum amount out (slippage protection)

Example:

"1450000000"

chainId
number
required

Chain ID

Example:

1

deadline
number

Deadline timestamp (optional, defaults to 20 minutes from now)

Example:

1234567890

Response

Swap transaction prepared successfully

success
boolean
required

Success status

Example:

true

serializedTransaction
string
required

Serialized transaction data

gasEstimation
object
required

Gas estimation

expectedAmountOut
string
required

Expected output amount

Example:

"1500000000"

message
string
required

Response message

Example:

"Swap transaction prepared successfully"

approvalTransaction
string

Approval transaction if needed