Skip to content

hiero-ledger/hiero-sdk-swift

Hiero Swift SDK

OpenSSF Scorecard CII Best Practices License

The Swift SDK for interacting with Hiero-based networks.

Maintained with ❤️ by Hashgraph and the Hiero community.


Table of Contents


Requirements

Platform Minimum Version
Swift 5.6+ (6.0+ recommended)
macOS 10.15+ (Catalina, 2019)
iOS 13+ (2019)

⚠️ Deprecation Notice: Swift 5.x support is deprecated and will be removed in a future release. Please migrate to Swift 6.0+.


Installation

Add the Hiero SDK to your Swift package dependencies:

// Package.swift
dependencies: [
    .package(url: "https://github.com/hiero-ledger/hiero-sdk-swift.git", from: "0.36.0")
]

For Xcode projects, see Apple's guide on Adding Package Dependencies to Your App.


Quick Start

import Hiero

// Connect to a Hiero network (testnet, mainnet, etc.)
let client = Client.forTestnet()

// Query the balance of an account
let balance = try await AccountBalanceQuery()
    .accountId(AccountId("0.0.1001")!)
    .execute(client)

print("Balance: \(balance.hbars)")

Examples

The SDK includes example applications in the Examples directory demonstrating accounts, tokens, consensus topics, files, smart contracts, scheduling, and more.

# Run an example
task example name=<ExampleName>

# For example:
task example name=CreateAccount
task example name=GetAccountBalance

Development

Required Tooling

Tool Source
protoc Protocol Buffers compiler
protoc-gen-swift apple/swift-protobuf
protoc-gen-grpc-swift grpc/grpc-swift
task go-task/task
python3 For proto generation scripts

Generating Protobufs

The HieroProtobufs module is entirely generated from the hiero-consensus-node protobufs.

# Fetch the latest protobufs and generate Swift code
task submodule:fetch

# Or fetch a specific version
task submodule:fetch proto=v0.61.0

Testing

See Tests/README.md for comprehensive testing documentation.

Quick Start

# Unit tests (no network required)
swift test --filter HieroUnitTests

# Integration tests (requires environment configuration)
swift test --filter HieroIntegrationTests

# All tests
swift test

# Run a specific test
swift test --filter AccountCreateTransactionUnitTests/test_Serialize

Environment Configuration

Create a .env file in the project root for integration tests:

# Required: Operator account credentials
HIERO_OPERATOR_ID=0.0.1234
HIERO_OPERATOR_KEY=302e020100300506032b657004220420...

# Environment type: testnet, previewnet, mainnet, or custom
HIERO_ENVIRONMENT_TYPE=testnet

Testing with Solo

For local development and testing, we recommend using Hiero Solo. Solo provides a lightweight, local Hiero network running in Kubernetes.

# Solo environment configuration
HIERO_OPERATOR_ID=0.0.2
HIERO_OPERATOR_KEY=3030020100300706052b8104000a042204205bc004059ffa2943965d306f2c44d266255318b3775bacfec42a77ca83e998f2
HIERO_ENVIRONMENT_TYPE=custom
HIERO_CONSENSUS_NODES=127.0.0.1:50211,127.0.0.1:51211
HIERO_CONSENSUS_NODE_ACCOUNT_IDS=0.0.3,0.0.4
HIERO_MIRROR_NODES=127.0.0.1:5600

Note: Some tests that trigger address book updates require /etc/hosts entries for Kubernetes DNS names. See Tests/README.md for details.


Contributing

We welcome contributions from the community! Please refer to the Hiero contribution guidelines before getting started.


Community


License

This project is licensed under the Apache License, Version 2.0. See LICENSE for details.

About

Swift SDK for Hiero

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 16

Languages