Hinkal Mobile SDK
Quickstart
Integrate private token transfers into your iOS app in a few minutes.
Note
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.
Installation
Add the SDK with Swift Package Manager. In Xcode: File → Add Package Dependencies…, then enter:
https://github.com/Hinkal-Protocol/hinkal-sdkSelect version 0.1.4 and add the Hinkal library to your target. SPM downloads and verifies the prebuilt binary automatically. Full detail in Installation.
import HinkalQuick Example
1. Implement the host wallet
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:
func call<T>(_ body: (_ err: inout NSError?) -> T) throws -> T {
var err: NSError?
let result = body(&err)
if let err { throw err }
return result
}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
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
}
}