Skip to content

Commit

Permalink
docs: update usage example in README, show how to depend on dep
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode authored Jun 4, 2022
1 parent dc8ca7a commit e0d6576
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
dependencies: [
.package(url: "https://github.com/hashgraph/hedera-sdk-swift.git", from: "0.1.0")
]
targets: [
.executableTarget(
name: "MyApp",
dependencies: [
// your other dependencies
.product(name: "Hedera", package: "hedera-sdk-swift")
],
// allows for using `@main` in a swift file built with swift package manager
swiftSettings: [
.unsafeFlags([
"-parse-as-library"
])
]),
]
```

See ["Adding Package Dependencies to Your App"](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app) for help on
Expand All @@ -28,17 +42,33 @@ adding a swift package to an Xcode project.
## Usage

```swift
// main.swift
import Hedera

// connect to the Hedera network
let client = Client.forTestnet()
@main
public enum Program {
public static func main() async throws {
let client = Client.forTestnet()

client.setPayerAccountId(AccountId(num: ...))
client.addDefaultSigner(PrivateKey("...")!)

let newKey = PrivateKey.generateEd25519()

print("private key = \(newKey)")
print("public key = \(newKey.publicKey)")

let response = try await AccountCreateTransaction()
.key(.single(newKey.publicKey))
.initialBalance(500_000_000)
.execute(client)

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

print("balance = \(ab.balance)")
print("account address = \(newAccountId)")
}
}
```

See [examples](./Examples) for more usage.
Expand Down

0 comments on commit e0d6576

Please sign in to comment.