Swiftpack.co - Package - nervosnetwork/ckb-sdk-swift

CKB SDK Swift

Platform Azure Pipelines TravisCI Codecov Telegram Group

Swift SDK for Nervos CKB.

Prerequisites

  • Xcode 10.2 with Swift 5, 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/nervosnetwork/ckb-sdk-swift.git", tag: "v0.19.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/nervosnetwork/ckb-sdk-swift", from: "0.19.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

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

Github

link
Stars: 9
Help us keep the lights on

Releases

v0.23.1 - Oct 19, 2019

v0.23.1 (2019-10-19)

Features

  • Set default fee to 1000 shannons

v0.23.0 - Oct 19, 2019

v0.23.0 (2019-10-19)

Bug Fixes

v0.22.0 - Oct 5, 2019

v0.22.0 (2019-10-05)

Features

  • Parse header/epoch compact target field as hex string (5f8f832)
  • Update header and epoch structures (ec0deaa)
  • Update Script.args and Transaction.witnesses type (95e16d2)

BREAKING CHANGES

  • header and epoch structures are changed as per CKB update.

Note: field compact_target is output from RPC as uint32, but they should be hex string to follow the convention. Await CKB to fix that.

  • Bytes serialization are used for these two structures. Before this [Bytes] serialization were used. This affects script and transaction hash calculation and transaction signing.

v0.21.2 - Sep 24, 2019

v0.21.2 (2019-09-24)

Features

  • Payment could be assigned a block number (09b94d6)

v0.21.1 - Sep 23, 2019

v0.21.1 (2019-09-23)

Features

  • Allow live cell collector to accept a from block number param (560d1b3)
  • Return last block around which live cells are scanned (079a169)