CKB

0.29.0

Swift toolkit for Nervos CKB
ashchan/ckb-swift-kit

What's New

v0.29.0

2020-03-07T10:05:09Z

v0.29.0 (2020-03-07)

  • Update CryptoSwift to 1.3.0

CKB SDK Swift

Platform Azure Pipelines

Swift SDK for Nervos CKB.

The ckb-sdk-swift is still under development and NOT production ready. You should get familiar with CKB transaction structure and RPC before using it.

Prerequisites

  • Xcode 12.1 with Swift 5.1, or higher
  • Target of iOS 11 or higher / macOS 10.13 or higher
  • CocoaPods or SPM

Installation

CocoaPods

Install CocoaPods 1.7.0 or later.

Add this to your Podfile:

platform :osx, "10.13"

target "MyApp" do
  use_frameworks!
  use_modular_headers!

  pod "CKB", git: "https://github.com/ashchan/ckb-sdk-swift.git", tag: "v0.25.0"
end

Swift Package Manager(SPM)

You can also use Swift Package Manager. In your Package.swift file, specify this in dependencies:

dependencies: [
  .package(url: "https://github.com/ashchan/ckb-sdk-swift", from: "0.25.0")
]

Getting Started

Note: Many API methods would throw exception on failure. The following examples all assume that there's a surrounding do {} catch {} block or throwing function.

The APIClient class provides JSONRPC access to a CKB node.

import CKB

// Connect to local node
let nodeUrl = URL(string: "http://localhost:8114")!
let apiClient = APIClient(url: nodeUrl)

// Fetch local node info
let nodeInfo = try apiClient.localNodeInfo()
print(nodeInfo.version)                        // "0.20.0 (rylai-v9 024408ee 2019-09-07)"

// Get current height
let height = try apiClient.getTipBlockNumber() // Numbers are represented as strings
print(height)                                  // "10420"

Send Capacity Example (Using Payment class)

let payment = try! Payment(
    from: "ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83",
    to: "ckt1qyqy0frc0r8kus23ermqkxny662m37yc26fqpcyqky",
    amount: 100  * 100_000_000,
    apiClient: APIClient(url: nodeUrl)
)

let privateKey = Data(hex: "e79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3")
try payment.sign(privateKey: privateKey)
if let txhash = try? payment.send() {
    print(txhash)
}

Getting Help

Changelog

See CHANGELOG.md file.

License

CKB Swift SDK is released under the terms of the MIT license. See LICENSE for more information or see https://opensource.org/licenses/MIT.

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

Last updated: Wed Nov 29 2023 16:55:23 GMT-1000 (Hawaii-Aleutian Standard Time)