Hinkal Mobile SDK

Error Handling Patterns

Patterns for handling failures robustly in production.

Centralize error surfacing

Route all SDK calls through a single helper so messages are handled consistently:

inline fun <T> run(op: () -> T): Result<T> =
    try { Result.success(op()) } catch (e: Exception) { Result.failure(e) }

val result = run { hinkal.deposit(chainId, tokens, amounts, true, false) }

Distinguish user error from system error

  • User-correctable - bad amount, invalid recipient, insufficient balance. Validate up front (see Error Handling) and prompt the user to fix the input.
  • Transient - network or relayer errors. Offer a retry.
  • Fatal - a failed session handshake. Prompt the user to reconnect the wallet.

Retry safely

Reads (getTotalBalance, quotes) are safe to retry. For fund-moving calls, confirm the previous attempt did not land before retrying - re-read the balance with resetCache = true first.

Recover stuck funds

If a scheduled operation is interrupted, funds can end up in blocked UTXOs. Detect with getStuckShieldedBalances and recover with withdrawStuckUtxos (see Balances).