Latest 0.4.2
Homepage https://github.com/BitskiCo/bitski-ios
License MIT
Platforms ios 11.0
Dependencies Web3, Web3/ContractABI, Web3/PromiseKit, AppAuth, BigInt.swift, secp256k1.swift, PromiseKit/CorePromise
Authors

Bitski iOS SDK

CocoaPods
CocoaPods
CocoaPods
Documentation
Codecov

The official Bitski SDK for iOS. Build decentralized iOS apps with Ethereum with OAuth-based cross-platform wallet.

Example

To run the example project, clone the repo, and run pod install from the Example directory first. You’ll need to add your client id and redirect url to AppDelegate.

Requirements

  • Currently only supports iOS 11 and above

Installation

Bitski is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Bitski'

Usage

Initialization

First, get a client ID by creating an app here. Make sure you select ‘Native App’ for App Type.

You’ll also need to add the redirectURL you use in the app under Redirect URLs in the developer portal. This ensures that only urls that you trust can be used with your client id.

In your app, you’ll initialize an instance of Bitski:

// Replace redirect URL with an url scheme that will hit your native app
Bitski.shared = Bitski(clientID: "<YOUR CLIENT ID>", redirectURL: URL(string: "exampleapp://application/callback")!)

We provide a convenient static place to initialize your instance in Bitski.shared, but if you want to avoid using a singleton you can store your instance however
works best for you.

Authentication

Once you have an instance of Bitski configured, you can check the signed in status. The user will need to be logged in before making any Web3 calls.

if Bitski.shared?.isLoggedIn == true {
    self.web3 = Bitski.shared?.getWeb3()
    // show logged in state
} else {
    // show logged out state
}

To sign in, simply call signIn() (this will open a browser window):

Bitski.shared?.signIn() { error in
    // Once signed in, get an instance of Web3
    self.web3 = Bitski.shared?.getWeb3()
    // or, specify a network with getWeb3(network:)
}

A user will remain signed in indefinitely, unless the access token is revoked. To explicitly sign out:

Bitski.shared?.signOut()

Local Dev

If you’re developing locally (like with truffle develop or ganache), you can use the development network instead.

let network: Bitski.Network = .development(url: "http://localhost:9545") //or use your local IP if building for a device.
let web3 = Bitski.getWeb3(network: network)

Handling Implicit Logouts

Notifications will be posted when the user is signed in and signed out (Bitski.LoggedInNotification and Bitski.LoggedOutNotification) respectively.
A user can be signed out either explicitly, or implicitly if the access token is revoked. Therefore, it’s a good practice to respond to these notifications.

NotificationCenter.default.addObserver(self, selector: #selector(userDidLogout), name: Bitski.LoggedOutNotification, object: nil)

Using Web3

Once you have an instance of Web3 intialized, you can use it to make Ethereum calls and transactions. We provide full access to the Ethereum network through
our API.

// Example: Make a simple transfer transaction
firstly {
    web3.eth.accounts().firstValue
}.then { account in
    let to = EthereumAddress(hex: "SOME ADDRESS", eip55: false)
    let transaction = EthereumTransaction(gasLimit: 21000, from: account, to: to, value: EthereumQuantity(quantity: 1.eth))
    return web3.eth.sendTransaction(transaction: transaction)
}.then { transactionHash in
    web3.eth.getTransactionReceipt(transactionHash)
}.done { receipt in
    let watcher = TransactionWatcher(hash: transactionHash, web3: web3)
    watcher.expectedConfirmations = 3
    watcher.delegate = self
    self.transactionWatcher = watcher
}

For more about what you can do in Web3, see Web3.swift.

Authorization

Our Web3 provider lets you send transactions to be signed, but the user must explictly approve them. For security, this authorization happens in our web UI
and will display as a browser modal above your application. Once the transaction has been approved or rejected, the modal will dismiss.
For the best experience we recommend limiting the amount of transactions you send.

License

Bitski is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Bitski",
    "version": "0.4.2",
    "summary": "Bitski SDK for iOS. Interact with Ethereum wallets using simple OpenID auth.",
    "description": "Provides tools for connecting to Ethereum wallets,ncreating transactions, and interacting with the Ethereumnnetwork through Web3.swift and OpenID Connect.",
    "homepage": "https://github.com/BitskiCo/bitski-ios",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Josh Pyles": "[email protected]"
    },
    "source": {
        "git": "https://github.com/BitskiCo/bitski-ios.git",
        "tag": "0.4.2"
    },
    "platforms": {
        "ios": "11.0"
    },
    "swift_version": "4.0",
    "source_files": "Bitski/Classes/**/*",
    "exclude_files": "docs/**/*",
    "dependencies": {
        "Web3": [
            "~> 0.3.1"
        ],
        "Web3/ContractABI": [
            "~> 0.3.1"
        ],
        "Web3/PromiseKit": [
            "~> 0.3.1"
        ],
        "AppAuth": [
            "~> 0.93"
        ],
        "BigInt.swift": [
            "~> 1.0"
        ],
        "secp256k1.swift": [
            "~> 0.1"
        ],
        "PromiseKit/CorePromise": [
            "~> 6.0"
        ]
    }
}

Pin It on Pinterest

Share This