Swiftpack.co - Package - yenom/BitcoinKit

BitcoinKit: Let’s Play with Bitcoin in Swift!

CI Status codecov Carthage compatible Version Platform Backers on Open Collective Sponsors on Open Collective

Welcome to BitcoinKit

The BitcoinKit library is a Swift implementation of the Bitcoin protocol, supporting both of BCH and BTC. Our mission is improving the mobile ecosystem for Bitcoin developers.

It allows maintaining a wallet and sending/receiving transactions without needing a full blockchain node. It comes with a simple wallet app showing how to use it.

Release notes are here.



  • Encoding/decoding addresses: base58, Cashaddr, P2PKH, P2SH, WIF format.
  • Transaction building blocks: inputs, outputs, scripts.
  • EC keys and signatures.
  • BIP32, BIP44 hierarchical deterministic wallets.
  • BIP39 implementation.
  • SPV features are under construction. The following functions cannot work well sometimes.
    • Send/receive transactions.
    • See current balance in a wallet.


Generate addresses

// from Testnet Cashaddr
let cashaddrTest = try AddressFactory.create("bchtest:pr6m7j9njldwwzlg9v7v53unlr4jkmx6eyvwc0uz5t")

// from Mainnet Cashaddr
let cashaddrMain = try AddressFactory.create("bitcoincash:qpjdpjrm5zvp2al5u4uzmp36t9m0ll7gd525rss978")

// from Base58 format
let address = try AddressFactory.create("1AC4gh14wwZPULVPCdxUkgqbtPvC92PQPN")

Creating new wallet

let privateKey = PrivateKey(network: .testnet) // You can choose .mainnet or .testnet
let wallet = Wallet(privateKey: privateKey)

Import wallet from WIF

let wallet = try Wallet(wif: "92pMamV6jNyEq9pDpY4f6nBy9KpV2cfJT4L5zDUYiGqyQHJfF1K")

Hierarchical Deterministic Wallet

// Generate mnemonic
let mnemonic = try Mnemonic.generate()

// Generate seed from the mnemonic
let seed = Mnemonic.seed(mnemonic: mnemonic)

let wallet = HDWallet(seed: seed, network: .testnet)

Key derivation

let mnemonic = try Mnemonic.generate()
let seed = Mnemonic.seed(mnemonic: mnemonic)

let privateKey = HDPrivateKey(seed: seed, network: .testnet)

// m/0'
let m0prv = try! privateKey.derived(at: 0, hardened: true)

// m/0'/1
let m01prv = try! m0prv.derived(at: 1)

// m/0'/1/2'
let m012prv = try! m01prv.derived(at: 2, hardened: true)

HD Wallet Key derivation

let keychain = HDKeychain(seed: seed, network: .mainnet)
let privateKey = try! keychain.derivedKey(path: "m/44'/1'/0'/0/0")

Extended Keys

let extendedKey = privateKey.extended()

Sync blockchain

let blockStore = try! SQLiteBlockStore.default()
let blockChain = BlockChain(network: .testnet, blockStore: blockStore)

let peerGroup = PeerGroup(blockChain: blockChain)
let peerGroup.delegate = self

let peerGroup.start()


  • iOS 9.0+ / Mac OS X 10.11+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 9.0+
  • Swift 4.1+



CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.5.0+ is required to build BitcoinKit.

To integrate BitcoinKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'

target '<Your Target Name>' do
    pod 'BitcoinKit'

Then, run the following command:

$ pod install


Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate BitcoinKit into your Xcode project using Carthage, specify it in your Cartfile:

github "yenom/BitcoinKit"

Run carthage update to build the framework and drag the built BitcoinKit.framework into your Xcode project.

Swift Package Manager

BitcoinKit is available through Swift Package Manager. To install it, simply add the following lines to dependencies of your Package.swift:

.package(url: "https://github.com/yenom/BitcoinKit.git", .upToNextMinor(from: "0.1.0"))

Note that following data types and features are currently not supported on Linux platform.

  • Peer and PeerGroup
  • SQLite based BlockStore


Contributions to BitcoinKit are welcome and encouraged! Feel free to open issues, drop us pull requests.

Authors & Maintainers


BitcoinKit is maintained and funded by Yenom. Visit our website or say hi on twitter (@Yenom_wallet_en)


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


This project exists thanks to all the people who contribute.


Thank you to all our backers! 🙏 [Become a backer]


Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]


Stars: 636
Help us keep the lights on

Used By

Total: 1


v1.1.0-beta3 - Sep 27, 2018

  • Update properties name and access modifiers of MDKeychain

v1.1.0-beta2 - Sep 21, 2018

  • Refactor MockUnlockScriptBuilder

v1.1.0-beta1 - Sep 20, 2018

Wallet class become super convenient class! You can create wallet application with only 10 lines.

  • Binary build is available now!
  • Wallet class is super convenience
  • Generating QRCode is super easy now. PrivateKey, PublicKey, Address has .qrImage()

Easiest way of receiving and sending Bitcoin ever.

// 1. Create Private Key, Publick Key, Address
let privkey: PrivateKey = PrivateKey(network: .mainnet)
let pubkey: PublicKey = privkey.publicKey()
let address: Cashaddr = pubkey.toCashaddr()
let qrImage: UIImage? = address.qrImage(size: CGSize(width: 240, height: 240))

// 2. Create Wallet, Get balance, Refresh balance
let wallet: Wallet = Wallet(privateKey: privkey,
                            walletDataStore: UserDefaults.standard)
let balance = wallet.balance

// 3. Send Bitcoin
let toAddress = try! AddressFactory.create("bitcoincash:qz936smm809wq0eqthqyh2sgdzhs7v08nvnuq0dmps")
wallet.send(to: toAddress, amount: 10000)

v1.0.2 - Sep 6, 2018

Thanks everyone involved!

  • Added Multisig Script Mock!
  • Added isCoinbase() in Transaction class by @federicobond
  • Fix some typo by @federicobond
  • Add HeadersMessage by @akifuj
  • Add open collective committers and backers by @monkeywithacupcake

v1.0.1 - Aug 17, 2018

Added ScriptFactory!