Swaps
A private swap trades one token for another entirely inside the private balance, with no public trace of the trade. It runs server-side through a Hinkal relayer.
Quote first
Get a quote before swapping. Use getEvmSwapPrices on EVM chains, getSolanaSwapPrices on Solana:
val quoteJson = hinkal.getEvmSwapPrices(chainId, inWei, inToken, outToken)The quote returns the swap data you pass into swap.
Basic Swap
val txHash = hinkal.swap(
chainId,
"[\"$inToken\", \"$outToken\"]",
"[\"$inWei\"]",
actionID,
swapData,
inToken, // feeToken
"", // feeStructureJSON
)On Solana use swapSolana(...), which omits actionID:
val txHash = hinkal.swapSolana(
chainId,
"[\"$inToken\", \"$outToken\"]",
"[\"$inWei\"]",
swapData,
outToken, // feeToken
"", // feeStructureJSON
)Parameters
| Parameter | Type | Description |
|---|---|---|
chainID | Long | Target chain id. |
tokenAddrsJSON | String | JSON array: input token, then output token. |
amountsWeiJSON | String | JSON array with the input amount in wei. |
actionID | String | DEX action id from the quote (EVM only). |
swapData | String | Encoded swap data from the quote. |
feeToken | String | Token the fee is paid in. |
feeStructureJSON | String | Fee quote, or empty for defaults. |
Error Handling
try {
val txHash = hinkal.swap(chainId, "[\"$inToken\", \"$outToken\"]", "[\"$inWei\"]",
actionID, swapData, inToken, "")
} catch (e: Exception) {
Log.e("Hinkal", "Swap failed: ${e.message}")
}Best Practices
1. Always quote immediately before swapping
Quotes move. Fetch a fresh quote with getEvmSwapPrices / getSolanaSwapPrices right before calling swap, and pass its swapData unchanged.
val quote = hinkal.getEvmSwapPrices(chainId, inWei, inToken, outToken)2. Use the right method per chain
Use swap on EVM/Tron (it takes actionID) and swapSolana on Solana (no actionID). Branch on Mobile.isSolanaChain(chainId).
3. Refresh the balance afterward
hinkal.getTotalBalance(chainId, signature, address, true, false)