> For the complete documentation index, see [llms.txt](https://hinkal-team.gitbook.io/hinkal/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hinkal-team.gitbook.io/hinkal/hinkal-mobile-sdk/ios/guides/deposits.md).

# 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.

```swift
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

| Parameter        | Type     | Description                                              |
| ---------------- | -------- | -------------------------------------------------------- |
| `chainID`        | `Int64`  | Target chain id.                                         |
| `tokenAddrsJSON` | `String` | JSON array of token addresses.                           |
| `amountsWeiJSON` | `String` | JSON array of amounts in wei, matching `tokenAddrsJSON`. |
| `preEstimateGas` | `Bool`   | Estimate gas before submitting.                          |
| `returnTxData`   | `Bool`   | Return unsigned tx data instead of broadcasting.         |

### Depositing multiple tokens

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

```swift
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`:

```swift
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:

```swift
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.

```swift
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

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