Hinkal Mobile SDK

Deposits

A deposit moves tokens from the public wallet into the shielded balance (public → private). It is signed and broadcast through your host wallet.

Basic Deposit

SDK calls take an NSError out-parameter, wrapped here with the call helper from Getting Started.

let wei = try call { MobileAmountToWei(chainId, tokenAddress, "1.0", &$0) }
let txHash = try call {
    hinkal.deposit(
        chainId,
        tokenAddrsJSON: "[\"\(tokenAddress)\"]",
        amountsWeiJSON: "[\"\(wei)\"]",
        preEstimateGas: true,
        returnTxData: false,
        error: &$0
    )
}
print("Deposit tx:", txHash)

Parameters

ParameterTypeDescription
chainIDInt64Target chain id.
tokenAddrsJSONStringJSON array of token addresses.
amountsWeiJSONStringJSON array of amounts in wei, matching tokenAddrsJSON.
preEstimateGasBoolEstimate gas before submitting.
returnTxDataBoolReturn unsigned tx data instead of broadcasting.

Depositing multiple tokens

Because tokens and amounts are JSON arrays, one call deposits several tokens at once:

let usdcWei = try call { MobileAmountToWei(chainId, usdc, "100", &$0) }
let wethWei = try call { MobileAmountToWei(chainId, weth, "0.5", &$0) }
let txHash = try call {
    hinkal.deposit(
        chainId,
        tokenAddrsJSON: "[\"\(usdc)\", \"\(weth)\"]",
        amountsWeiJSON: "[\"\(usdcWei)\", \"\(wethWei)\"]",
        preEstimateGas: true,
        returnTxData: false,
        error: &$0
    )
}

Parsing amounts

Amounts cross the boundary in base units (wei). Convert with MobileAmountToWei, and back with MobileAmountFromWei:

let wei = try call { MobileAmountToWei(chainId, tokenAddress, "1.5", &$0) }   // human → wei
let human = try call { MobileAmountFromWei(chainId, tokenAddress, wei, &$0) } // wei → human

Error Handling

The call helper rethrows the framework's NSError, so a normal do/catch works:

do {
    let txHash = try call {
        hinkal.deposit(chainId, tokenAddrsJSON: "[\"\(tokenAddress)\"]", amountsWeiJSON: "[\"\(wei)\"]",
                       preEstimateGas: true, returnTxData: false, error: &$0)
    }
} catch {
    print("Deposit failed:", error.localizedDescription)
}

Best Practices

1. Validate the amount before submitting

MobileAmountToWei throws if the token has fewer decimals than provided - convert first.

let wei = try call { MobileAmountToWei(chainId, tokenAddress, amountText, &$0) }

2. Ensure the wallet is funded

A deposit is broadcast by your host wallet, so it needs the token balance plus native gas (and, for ERC-20, an allowance to the Hinkal contract).

3. Refresh the balance afterward

_ = try call { hinkal.getTotalBalance(chainId, userKeysSignature: signature,
    ethAddress: address, resetCache: true, useBlockedUtxos: false, error: &$0) }