v2

OpenAPI 3.1.02026-07-3139137119.0 KB
swap

Execute Swap

Create the payment details for a SWAP-mode order — returns the deposit instruction (payment block with steps to fund).

post/swap/execute

Headers

X-API-KEYstring required

API key for authentication

Request body

trade_type'EXACT_INPUT' | 'EXACT_OUTPUT' required

Whether the source or destination amount is fixed.

amountstring required
use_deposit_addressboolean

When true, steps[] always carries a deposit instruction; when omitted steps can be of various types depending on the swap route.

Example request

{
  "amount": "100.0",
  "destination": {
    "currency": {
      "address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
      "chain_id": 30000000000001
    },
    "recipient": "0x1234...abcd"
  },
  "metadata": {
    "items": [
      {
        "currency": "USD",
        "description": "High-quality widget with extra features",
        "image": "https://example.com/images/widget.png",
        "name": "Premium Widget",
        "quantity": 2,
        "unit_price": 49.99
      }
    ],
    "refund": {
      "additional_info": "Item was never shipped",
      "currency": "USD",
      "name": "Order Cancellation",
      "reason": "Customer requested refund",
      "refund_amount": 99.98
    }
  },
  "source": {
    "currency": {
      "address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
      "chain_id": 30000000000001
    },
    "sender_address": "0x1234...abcd",
    "slippage_bps": 50
  },
  "trade_type": "EXACT_OUTPUT",
  "use_deposit_address": false
}

Response

Swap order created; fund the deposit

order_idstring required
status'PENDING' | 'EXPIRED' | 'FAILED' | 'AWAITING_PAYMENT' | 'OPTIMISTIC_CONFIRMED' | 'AWAITING_CONFIRMATION' | 'EXECUTING_ORDER' | 'COMPLETED' | 'REFUNDED' | 'PARTIAL_PAYMENT' required

Example response

{
  "data": {
    "destination_tx_hash": "0x5678...efgh",
    "estimated_duration_seconds": 120,
    "expires_at": "2023-01-01T00:00:00Z",
    "fee_tx_hash": "0xfee1...fee2",
    "input": {
      "amount": {
        "raw": "100000000",
        "ui": "100.0",
        "value_usd": 100
      },
      "balance": {
        "raw": "100000000",
        "ui": "100.0",
        "value_usd": 100
      },
      "breakdown": {
        "base": {
          "raw": "100000000",
          "ui": "100.0",
          "value_usd": 100
        },
        "fees": {
          "custom_fee": {
            "raw": "100000000",
            "ui": "100.0",
            "value_usd": 100
          },
          "protocol_fee": {
            "raw": "100000000",
            "ui": "100.0",
            "value_usd": 100
          },
          "relayer_fee": {
            "raw": "100000000",
            "ui": "100.0",
            "value_usd": 100
          },
          "total_fee": {
            "raw": "100000000",
            "ui": "100.0",
            "value_usd": 100
          }
        },
        "gas": {
          "raw": "100000000",
          "ui": "100.0",
          "value_usd": 100
        },
        "total": {
          "raw": "100000000",
          "ui": "100.0",
          "value_usd": 100
        }
      },
      "currency": {
        "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
        "chain_id": 1,
        "decimals": 6,
        "id": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48-1",
        "name": "USD Coin",
        "price_usd": 1,
        "symbol": "USDC"
      }
    },
    "output": {
      "amount": {
        "raw": "100000000",
        "ui": "100.0",
        "value_usd": 100
      },
      "amount_out_minimum": {
        "raw": "100000000",
        "ui": "100.0",
        "value_usd": 100
      },
      "currency": {
        "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
        "chain_id": 1,
        "decimals": 6,
        "id": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48-1",
        "name": "USD Coin",
        "price_usd": 1,
        "symbol": "USDC"
      }
    },
    "payment_rail": "CRYPTO",
    "recipient": "0x1234...abcd",
    "refund": {
      "address": "0x1234...abcd",
      "reason": "execution failed: provider error",
      "tx_hash": "0x9abc...ijkl"
    },
    "source_tx_hash": "0x1234...abcd",
    "steps": [
      {
        "action": "swap",
        "kind": "deposit",
        "rail": "CRYPTO"
      }
    ]
  }
}