---
title: "Get swap quote with energy delegation"
method: POST
path: "/api/v2/agent/swap"
tags: ["Swap"]
---

# Get swap quote with energy delegation

`POST /api/v2/agent/swap`

## Request

- Base URL: `https://powersun.vip`
- URL: `https://powersun.vip/api/v2/agent/swap`
- Auth: one of:
  - API key in header `X-API-Key`
  - none

Get a price quote and unsigned transaction for swapping tokens on SunSwap DEX with automatic energy delegation. Sign the returned unsignedTx and broadcast via /api/v2/agent/broadcast. Use X-API-Key to pay from TRX balance, or request without authentication for TRX 402 instructions. USDC x402 is supported only by /buy-energy.

## Request body

- object
  - `fromToken` string, required: Token to sell — symbol (TRX, USDT, SUN, ...) or TRC-20 contract address
  - `toToken` string, required: Token to buy — symbol or TRC-20 contract address
  - `amountIn` string, required: Amount in base units (SUN for TRX, 6 decimals for USDT)
  - `slippageBps` integer: Slippage tolerance in basis points (default: 50 = 0.5%)
  - `senderAddress` string: TRON address of the sender (defaults to registered address)

## Response `200`

Swap quote with unsigned transaction

- SwapQuote
  - `quote` object
    - `fromToken` string: Source token contract address
    - `toToken` string: Destination token contract address
    - `fromSymbol` string
    - `toSymbol` string
    - `amountIn` string: Input amount in base units
    - `expectedAmountOut` string: Expected output amount in base units
    - `amountOutMin` string: Minimum output with slippage
    - `slippageBps` integer: Slippage tolerance in basis points
    - `route` string[]: DEX routing path
    - `deadline` integer: Unix timestamp deadline
  - `energy` object
    - `estimatedUnits` integer
    - `costSun` integer
    - `costTrx` number
  - `unsignedTx` object: Unsigned TRON transaction to sign with your private key
  - `nextAction` object
    - `action` 'sign_and_broadcast'
    - `description` string
    - `broadcastUrl` string

## Other responses

- `402`: Payment required — TRX on TRON

---

[API](https://skmtc.dev/powersun/apis/powersun-agent-api.md) · [All operations](https://skmtc.dev/powersun/apis/powersun-agent-api/llms.txt) · [OpenAPI document](https://skmtc.dev/powersun/apis/powersun-agent-api/revisions/169cc1ebfd26?raw)
