Quickstart
MeroKit (import MeroKit) is the native Swift SDK for a remote
Calimero node. This page takes you
from adding the package to your first authenticated contract call.
Requirements
Section titled “Requirements”- Swift 5.9+ (built and tested on Swift 6)
- iOS 15+ / macOS 12+
- Zero third-party dependencies — built on
URLSession,Foundation, andSecurity.
Install
Section titled “Install”dependencies: [ .package(url: "https://github.com/calimero-network/swift-sdk.git", from: "0.1.0"),],targets: [ .target(name: "MyApp", dependencies: [ .product(name: "MeroKit", package: "swift-sdk"), // Optional SwiftUI frontend: .product(name: "MeroKitUI", package: "swift-sdk"), ]),]File → Add Package Dependencies…, paste
https://github.com/calimero-network/swift-sdk.git, and add the MeroKit
library product (and MeroKitUI if you want the SwiftUI layer).
# Podfilepod 'MeroKit'See MeroKit.podspec.
Your first calls
Section titled “Your first calls”-
Create the client. Point it at your node; persist tokens in the Keychain.
import MeroKitlet mero = Mero(config: MeroConfig(baseURL: URL(string: "https://your-node.example")!,tokenStore: KeychainTokenStore() // defaults to in-memory otherwise)) -
Authenticate with a username and password.
bootstrapSecretis only needed for the very first login on a fresh node.let tokens = try await mero.authenticate(Credentials(username: "alice", password: "s3cr3t"))let authed = await mero.isAuthenticated // true -
Call a contract over JSON-RPC. The result is decoded into your
Decodabletype; arguments are a[String: JSONValue]dictionary literal.struct Post: Decodable { let id: String; let title: String }let post: Post = try await mero.rpc.execute(contextId: "…",method: "get_post",argsJson: ["id": "42"]) -
Use the admin & auth APIs for everything else.
let contexts = try await mero.admin.getContexts()let providers = try await mero.auth.getProviders() -
Log out — clears the token bundle from memory and the store.
await mero.logout()
Handle errors
Section titled “Handle errors”Failures surface as a single MeroError enum (plus the contract’s own RPC
errors). Match the cases you care about:
do { let post: Post = try await mero.rpc.execute( contextId: "…", method: "get_post", argsJson: ["id": "42"] )} catch let error as MeroError { switch error { case .authRevoked: // refresh token reused/revoked — prompt re-login case .http(let http): print("HTTP \(http.status)") case .rpc(let rpc): print("contract error \(rpc.code): \(rpc.message)") default: print(error) }}See the error model for every case.
Next steps
Section titled “Next steps”- Authentication — direct login, Desktop SSO, and the token lifecycle.
- System overview — how the SDK is layered.
- Executing methods — the RPC client and
JSONValue. - SwiftUI frontend — drop-in
MeroClient+ views. - Try it live:
swift run MeroExampletours the whole SDK.