Hinkal Mobile SDK

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

ParameterTypeDescription
chainIDLongTarget chain id.
tokenAddrsJSONStringJSON array: input token, then output token.
amountsWeiJSONStringJSON array with the input amount in wei.
actionIDStringDEX action id from the quote (EVM only).
swapDataStringEncoded swap data from the quote.
feeTokenStringToken the fee is paid in.
feeStructureJSONStringFee 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)