Skip to content

hiero-ledger/hiero-sdk-swift

Hiero Swift SDK

OpenSSF Scorecard CII Best Practices License

The SDK for interacting with a Hiero based network.

Maintained with ❤️ by LaunchBadge, Hashgraph, and the Hiero community

Usage

Requirements

  • Swift v5.6+
  • MacOS v10.15+ (2019, Catalina)
  • iOS 13+ (2019)

Install

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

See "Adding Package Dependencies to Your App" for help on adding a swift package to an Xcode project.

Add to Code

import Hiero

// connect to the Hedera network
let client = Client.forTestnet()

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

print("balance = \(ab.balance)")

Development (HieroProtobufs)

HieroProtobufs are entirely generated.

Required Tooling

protoc protoc-gen-swift (from https://github.com/apple/swift-protobuf) protoc-gen-grpc-swift (from https://github.com/grpc/grpc-swift) task (from https://github.com/go-task/task) openSSL 3.4 (from https://openssl-library.org/source/)

Fetch Submodule and Generate Swift Protobufs (HieroProtobufs)

Update \protobufs submodule to latest changes.

# Fetch the latest version of the services submodule
# and generate swift code for Hiero protobufs and gRPC.
#
# Note: Append "proto=vX.Y.Z" to fetch a specific version
task submodule:fetch 

# e.g. move submodule to v0.61.0 tag
task submodule:fetch proto=v0.61.0

Examples

See examples for more usage.

# Run an example
$  task example name=<example>

# e.g CreateAccount
$  task example name=CreateAccount

Testing

See Tests/README.md for comprehensive testing documentation.

Quick Start:

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

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

# All tests
swift test

# Specific test
swift test --filter AccountCreateTransactionUnitTests/test_Serialize

Environment Setup for Integration Tests:

Create a .env file in the project root:

HIERO_OPERATOR_ID=0.0.1234
HIERO_OPERATOR_KEY=302e020100300506032b657004220420...
HIERO_ENVIRONMENT_TYPE=testnet

Local Node Testing:

For testing against hiero-local-node:

HIERO_OPERATOR_ID=0.0.2
HIERO_OPERATOR_KEY=3030020100300706052b8104000a042204205bc004059ffa2943965d306f2c44d266255318b3775bacfec42a77ca83e998f2
HIERO_ENVIRONMENT_TYPE=local

Contribute

Help/Community

About Users and Maintainers

License

  • Hiero's source code is available under the Apache License, Version 2.0 (Apache-2.0)

About

Swift SDK for Hiero

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 16

Languages