项目作者: keefertaylor

项目描述 :
TezosKit提供了一个基于Swift的工具箱,用于与Tezos区块链进行交互
高级语言: Swift
项目地址: git://github.com/keefertaylor/TezosKit.git
创建时间: 2018-09-30T00:35:33Z
项目社区:https://github.com/keefertaylor/TezosKit

开源协议:MIT License

下载


TezosKit

Build Status
codecov
Carthage Compatible
Version
License

TezosKit is a swift SDK that is compatible with the Tezos Blockchain. TezosKit implements complex interaction with the blockchain, including:

  • Performing preapplication for operations
  • Automatically revealing accounts as needed
  • Batching multiple operations

TezosKit provides native functionality to interact with a Tezos node or Conseil, an indexing service. TezosKit supports interaction with the chain via both closure based callbacks and Promises (PromiseKit) functionality.

TezosKit is compatible with both CocoaPods and Carthage. See the installation section below for specific instructions.

QuickStart

Wallets and Accounts

Accounts in Tezos are represented with Wallet objects.

To make a new wallet:

  1. let wallet = Wallet()!
  2. print("The wallet's mnemonic is \(wallet.mnemonic)")

To restore a wallet:

  1. let mnemonic = ...
  2. let wallet = Wallet(mnemonic: mnemonic)!

Interacting with the Tezos Node

The TezosNodeClient class supports interacting with a Tezos Node. Interaction can be done with closure callbacks or Promises.

  1. let tezosNodeClient = TezosClient()
  2. // Closure completion handler
  3. tezosNodeClient.getBalance(address: "KT1BVAXZQUc4BGo3WTJ7UML6diVaEbe4bLZA") { result in
  4. switch result {
  5. case .success(let balance):
  6. print("The balance of the contract is \(balance.humanReadableRepresentation)")
  7. case .failure(let error):
  8. print("Error getting balance: \(error)")
  9. }
  10. }
  11. // PromiseKit Promises
  12. tezosNodeClient.getBalance(address: "KT1BVAXZQUc4BGo3WTJ7UML6diVaEbe4bLZA").done { balance in
  13. print("The balance of the contract is \(balance.humanReadableRepresentation)")
  14. } .catch { _ in
  15. print("Couldn't get balance.")
  16. }

Learn more about interacting with a Tezos Node in the Tezos Node Documentation.

Interacting with Conseil

The ConseilClient class supports interacting with a Conseil service. Interaction can be done with closure callbacks or Promises.

  1. let conseilClent = ConseilClient(...)
  2. let address = "tz1iZEKy4LaAjnTmn2RuGDf2iqdAQKnRi8kY"
  3. // Closure completion handler
  4. conseilClient.originatedAccounts(from: address) { result in
  5. switch result {
  6. case .success(let originatedAccounts):
  7. print("Originated Accounts:")
  8. print(result)
  9. case .failure(let error):
  10. print("Error fetching originated accounts: \(error)")
  11. }
  12. }
  13. // PromiseKit Promises
  14. conseilClient.originatedAccounts(from: address).done { result in
  15. print("Originated Accounts:")
  16. print(result)
  17. } .catch { error in
  18. print("Error fetching originated accounts: \(error)")
  19. }

Learn more about interacting with a Conseil Service in the Conseil Documentation.

Advanced Usage

TezosKit is highly extensible for the needs of any individual project. Projects can customize RPCs and operations that are sent to the node. You can learn more about customizing TezosKit’s behavior in the Advanced Usage Documentation.

Installation

You may use either Carthage or Cocoapods to depend on TezosKit.

CocoaPods

TezosKit supports installation via CocoaPods. You can depened on TezosKit by adding the following to your Podfile:

  1. pod "TezosKit"

Carthage

If you use Carthage to manage your dependencies, simply add
TezosKit to your Cartfile:

  1. github "keefertaylor/TezosKit"

If you use Carthage to build your dependencies, make sure you have added Base58Swift.framework, BigInt.framework, MnemonicKit.framework, and PromiseKit.framework, Sodium.framework and TezosCrypto.framework, to the “Linked Frameworks and Libraries“ section of your target, and have included them in your Carthage framework copying build phase.

Bugs / Contributions

If you enounter bugs or missing features in TezosKit, please feel free to open a GitHub issue. You may want to check if the work you are suggesting is planned in future work.

Contributions and bug fixes are appreciated. Please open a PR for any missing or erroneous functionality for which you can contribute a fix.

To get started:
To get set up:

  1. $ brew install xcodegen # if you don't already have it
  2. $ xcodegen generate # Generate an XCode project from project.yml
  3. $ open TezosKit.xcodeproj

License

TezosKit is licensed under the permissive MIT licence.

See Also

  • TezosCrypto: A swift implementation of Tezos Cryptography