prepare_sunswap_swap
Construct an unsigned SunSwap V2 swap transaction on TRON, supporting TRX and TRC20 pairs with automatic allowance checks and slippage-based minimum output calculation.
Instructions
Build an unsigned SunSwap V2 same-chain swap on TRON. SunSwap V2 is a Uniswap-V2 fork; this tool routes through the V2 router (TNJVzGqKBWkJxJB5XYSqGAwUTV15U24pPq) using the standard swapExactETHForTokens / swapExactTokensForETH / swapExactTokensForTokens selectors based on which side is native TRX. Path encoding: TRX→TRC20 = [WTRX, toToken]; TRC20→TRX = [fromToken, WTRX]; TRC20→TRC20 = [fromToken, WTRX, toToken]. The builder (1) calls getAmountsOut on the router via /triggerconstantcontract to compute the expected output, (2) derives minOut as quotedOut * (10000 - slippageBps) / 10000, (3) for TRC-20 sources, reads allowance(wallet, router) and refuses with a recovery hint if insufficient — the user must run prepare_tron_trc20_approve(token, spender=router, amount) first, broadcast it, wait ~3s for it to land, then retry. (4) hand-rolls ABI calldata for the swap call (no SDK), (5) hits TronGrid /triggersmartcontract to build the tx, (6) verifies the returned raw_data_hex matches exactly what we asked for (selector + parameter + call_value + fee_limit) and refuses any drift. BLIND-SIGN on Ledger TRON app — the SunSwap router is not in the device's clear-sign allowlist. Enable "Allow blind signing" in the on-device TRON app Settings; the device shows the txID, which the user matches against the txID in the prepare receipt. Pair the Ledger via pair_ledger_tron first. Smart Router (V1+V2+V3+PSM aggregator) is intentionally not used — V2 router only — because Smart Router's mainnet address has not been published officially and its multi-version path encoding is a different ABI shape.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| wallet | Yes | TRON base58 wallet (T-prefixed, 34 chars) — funds the swap and signs the source tx on Ledger via USB. Pair via `pair_ledger_tron` first. | |
| fromToken | Yes | Source token. Either the literal string "TRX" for native TRX, OR a T-prefixed TRC-20 contract address. TRC-20 source REQUIRES a prior approve to the SunSwap V2 router (TNJVzGqKBWkJxJB5XYSqGAwUTV15U24pPq) — this tool checks allowance up-front and refuses with a recovery hint if insufficient. | |
| toToken | Yes | Destination token. Either the literal "TRX" or a T-prefixed TRC-20 contract address. Cannot equal fromToken. | |
| amount | Yes | Human-readable amount of fromToken (e.g. "100" for 100 TRX, "10.5" for 10.5 USDT). Decimals are resolved from the canonical TRC-20 set (USDT/USDC/USDD/TUSD) or from `fromTokenDecimals` for non-canonical tokens. | |
| slippageBps | No | Slippage tolerance in basis points (50 = 0.5%). Default 50. | |
| deadlineSeconds | No | Deadline window in seconds from now. Default 1200 (20 min). The router rejects the swap if it hasn't landed by then. | |
| fromTokenDecimals | No | REQUIRED when fromToken is a non-canonical TRC-20 (i.e. not USDT/USDC/USDD/TUSD or "TRX"). We refuse to guess decimals on a swap because an off-by-power-of-ten amountIn silently exposes the user to ~10^N-fold larger slippage than intended. | |
| toTokenDecimals | No | REQUIRED when toToken is a non-canonical TRC-20. Same reasoning as `fromTokenDecimals`. | |
| feeLimitTrx | No | Override the energy fee_limit cap (default 100 TRX). Pass a human-readable TRX amount (e.g. "50"). Energy estimate is reported separately in `estimatedEnergyCostSun`. |