> 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/quickstart.md).

# Quickstart

Integrate private token transfers into your iOS app in a few minutes.

{% hint style="info" %}
This quickstart gets you running fast with minimal explanation. For a detailed walkthrough see iOS Getting Started; for the full method list see iOS API Reference.
{% endhint %}

### Installation

Add the SDK with Swift Package Manager. In Xcode: **File → Add Package Dependencies…**, then enter:

```
https://github.com/Hinkal-Protocol/hinkal-sdk
```

Select version `0.1.1` and add the **Hinkal** library to your target. SPM downloads and verifies the prebuilt binary automatically. Full detail in Installation.

```swift
import Hinkal
```

### Quick Example

#### 1. Implement the host wallet

```swift
class WalletHost: NSObject, MobileHostWalletProtocol {
    let wallet: YourWalletImplementation

    func address(_ error: NSErrorPointer) -> String { wallet.address }
    func chainID() -> Int64 { wallet.chainId }
    func personalSign(_ message: String?, error: NSErrorPointer) -> String {
        wallet.personalSign(message ?? "")
    }
    func sendTransaction(_ toHex: String?, dataHex: String?, valueDec: String?,
                         gasLimit: Int64, error: NSErrorPointer) -> String {
        wallet.sendTransaction(toHex ?? "", dataHex ?? "", valueDec ?? "", gasLimit)
    }
    func switchChain(_ chainID: Int64) throws { try wallet.switchChain(chainID) }
}
```

#### 2. Connect and use the SDK

Throwing calls take an `NSError` out-parameter (the framework is generated by gomobile). Wrap them with a small rethrow helper:

```swift
func call<T>(_ body: (_ err: inout NSError?) -> T) throws -> T {
    var err: NSError?
    let result = body(&err)
    if let err { throw err }
    return result
}
```

```swift
import Hinkal

// 1. Create the client and connect - derives the shielded identity.
guard let client = MobileNewClient(), let hinkal = client.hinkal() else { return }
let address = try call { client.connect(WalletHost(wallet: yourWallet), error: &$0) }

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

// 3. Transfer (private → private)
let transferWei = try call { MobileAmountToWei(chainId, tokenAddress, "0.5", &$0) }
let transfer = try call {
    hinkal.transfer(chainId, tokenAddrsJSON: "[\"\(tokenAddress)\"]", amountsWeiJSON: "[\"\(transferWei)\"]",
                    recipient: recipientPrivateAddress, feeToken: tokenAddress, feeStructureJSON: "", error: &$0)
}

// 4. Withdraw (private → public)
let withdrawWei = try call { MobileAmountToWei(chainId, tokenAddress, "0.25", &$0) }
let withdraw = try call {
    hinkal.withdraw(chainId, tokenAddrsJSON: "[\"\(tokenAddress)\"]", amountsWeiJSON: "[\"\(withdrawWei)\"]",
                    recipient: recipientPublicAddress, relayerOff: false, feeToken: tokenAddress,
                    feeStructureJSON: "", error: &$0)
}
```

### SwiftUI Example

```swift
import SwiftUI
import Hinkal

struct ContentView: View {
    @StateObject private var viewModel = WalletViewModel()

    var body: some View {
        VStack {
            if viewModel.isConnected {
                Text(viewModel.address ?? "")
                Button("Deposit 1 Token") { Task { await viewModel.deposit() } }
                Button("Disconnect") { viewModel.disconnect() }
            } else {
                Button("Connect Wallet") { Task { await viewModel.connect() } }
            }
        }
    }
}

@MainActor
class WalletViewModel: ObservableObject {
    @Published var isConnected = false
    @Published var address: String?

    private var client: MobileClient?
    private var hinkal: MobileHinkal?

    func connect() async {
        client = MobileNewClient()
        hinkal = client?.hinkal()
        address = try? call { client?.connect(WalletHost(wallet: yourWallet), error: &$0) ?? "" }
        isConnected = address != nil
    }

    func deposit() async {
        guard let hinkal, let wei = try? call({ MobileAmountToWei(chainId, tokenAddress, "1.0", &$0) }) else { return }
        _ = try? call {
            hinkal.deposit(chainId, tokenAddrsJSON: "[\"\(tokenAddress)\"]",
                           amountsWeiJSON: "[\"\(wei)\"]", preEstimateGas: true, returnTxData: false, error: &$0)
        }
    }

    func disconnect() {
        try? client?.disconnect()
        isConnected = false
        address = nil
    }
}
```
