Bitcoin, BitcoinCash(ABC) and Dash wallet toolkit for Swift. This is a full implementation of SPV node including wallet creation/restore, synchronization with network, send/receive transactions, and more. The repository includes the main BitcoinCore.swift
and BitcoinKit.swift
, BitcoinCashKit.swift
and DashKit.swift
separate pods.
On this page, we'll use Kits to refer to one of BitcoinKit.swift
, BitcoinCashKit.swift
and DashKit.swift
kits.
Kits requires you to provide mnemonic phrase when it is initialized:
let words = ["word1", ... , "word12"]
let bitcoinKit = BitcoinKit(withWords: words, walletId: "bitcoin-wallet-id", syncMode: .api, networkType: .mainNet)
let bitcoinCashKit = BitcoinCashKit(withWords: words, walletId: "bitcoin-cash-wallet-id", syncMode: .api, networkType: .mainNet)
let dashKit = DashKit(withWords: words, walletId: "dash-wallet-id", syncMode: .api, networkType: .mainNet)
All 3 Kits can be configured to work in .mainNet
or .testNet
.
syncMode
parameterKits can restore existing wallet or create a new one. When restoring, it generates addresses for given wallet according to bip44 protocol, then it pulls all historical transactions for each of those addresses. This is done only once on initial sync. syncMode
parameter defines where it pulls historical transactions from. When they are pulled, it continues to sync according to SPV protocol no matter which syncMode was used for initial sync. There are 3 modes available:
.full
: Fully synchronizes from peer-to-peer network starting from the block when bip44 was introduced. This mode is the most private (since it fully complies with SPV protocol), but it takes approximately 2 hours to sync upto now (June 10, 2019)..api
: Transactions before checkpoint are pulled from API(currently Insight API or BcoinAPI). Then the rest is synchronized from peer-to-peer network. This is the fastest one, but it's possible for an attacker to learn which addresses you own. Checkpoints are updated with each new release and hardcoded so the blocks validation is not broken..newWallet
: No need to pull transactions.confirmationsThreshold
: Minimum number of confirmations required for an unspent output in incoming transaction to be spent (default: 6)minLogLevel
: Can be configured for debug purposes if required.Kits require to be started with start
command. It will be in synced state as long as it is possible. You can call stop
to stop it
bitcoinKit.start()
bitcoinKit.stop()
Kits hold all kinds of data obtained from and needed for working with blockchain network
Balance is provided in Satoshi
:
bitcoinKit.balance
// 2937096768
Last block info contains headerHash
, height
and timestamp
that can be used for displaying sync info to user:
bitcoinKit.lastBlockInfo
// ▿ Optional<BlockInfo>
// ▿ some : BlockInfo
// - headerHash : //"00000000000041ae2164b486398415cca902a41214cad72291ee04b212bed4c4"
// - height : 1446751
// ▿ timestamp : Optional<Int>
// - some : 1544097931
Get an address which you can receive coins to. Receive address is changed each time after you actually get a transaction in which you receive coins to that address
bitcoinKit.receiveAddress
// "mgv1KTzGZby57K5EngZVaPdPtphPmEWjiS"
Kits have transactions(fromHash: nil, limit: nil)
methods which return Single<TransactionInfo>
(for BitcoinKit and BitcoinCashKit) and Single<DashTransactionInfo>
(for DashKit) RX Single Observers.
TransactionInfo
:
// ▿ TransactionInfo
// - transactionHash : "0f83c9b330f936dc4a2458b7d3bb06dce6647a521bf6d98f9c9d3cdd5f6d2a73"
// - transactionIndex : 500000
// ▿ from : 2 elements
// ▿ 0 : TransactionAddressInfo
// - address : "mft8jpnf3XwwqhaYSYMSXePFN85mGU4oBd"
// - mine : true
// ▿ 1 : TransactionAddressInfo
// - address : "mnNS5LEQDnYC2xqT12MnQmcuSvhfpem8gt"
// - mine : true
// ▿ to : 2 elements
// ▿ 0 : TransactionAddressInfo
// - address : "n43efNftHQ1cXYMZK4Dc53wgR6XgzZHGjs"
// - mine : false
// ▿ 1 : TransactionAddressInfo
// - address : "mrjQyzbX9SiJxRC2mQhT4LvxFEmt9KEeRY"
// - mine : true
// - amount : -800378
// ▿ blockHeight : Optional<Int>
// - some : 1446602
// ▿ timestamp : Optional<Int>
// - some : 1543995972
DashTransactionInfo
:
// ▿ DashTransactionInfo
// - transactionHash : "0f83c9b330f936dc4a2458b7d3bb06dce6647a521bf6d98f9c9d3cdd5f6d2a73"
// - transactionIndex : 500000
// - instantTx : true
// ▿ from : 2 elements
// ▿ 0 : TransactionAddressInfo
// - address : "mft8jpnf3XwwqhaYSYMSXePFN85mGU4oBd"
// - mine : true
// ▿ 1 : TransactionAddressInfo
// - address : "mnNS5LEQDnYC2xqT12MnQmcuSvhfpem8gt"
// - mine : true
// ▿ to : 2 elements
// ▿ 0 : TransactionAddressInfo
// - address : "n43efNftHQ1cXYMZK4Dc53wgR6XgzZHGjs"
// - mine : false
// ▿ 1 : TransactionAddressInfo
// - address : "mrjQyzbX9SiJxRC2mQhT4LvxFEmt9KEeRY"
// - mine : true
// - amount : -800378
// ▿ blockHeight : Optional<Int>
// - some : 1446602
// ▿ timestamp : Optional<Int>
// - some : 1543995972
In order to create new transaction, call send(to: String, value: Int, feeRate: Int)
method on Kits
try bitcoinKit.send(to: "mrjQyzbX9SiJxRC2mQhT4LvxFEmt9KEeRY", value: 1000000, feeRate: 10000)
This first validates a given address and amount, creates new transaction, then sends it over the peers network. If there's any error with given address/amount or network, it raises an exception.
One can validate address and fee by using following methods:
try bitcoinKit.validate(address: "mrjQyzbX9SiJxRC2mQhT4LvxFEmt9KEeRY")
try bitcoinKit.fee(for: 1000000, toAddress: "mrjQyzbX9SiJxRC2mQhT4LvxFEmt9KEeRY", senderPay: true, feeRate: 10000)
senderPay
parameter defines who pays the fee
You can use parse
method to parse a BIP21 URI:
bitcoinKit.parse(paymentAddress: "bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=50&label=Luke-Jr&message=Donation%20for%20project%20xyz")
// ▿ BitcoinPaymentData
// - address : "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
// - version : nil
// ▿ amount : Optional<Double>
// - some : 50.0
// ▿ label : Optional<String>
// - some : "Luke-Jr"
// ▿ message : Optional<String>
// - some : "Donation for project xyz"
// - parameters : nil
Kits provide with data like transactions, blocks, balance, kits state in real-time. BitcoinCoreDelegate
protocol must be implemented and set to Kits instance to receive that data.
class Manager {
init(words: [String]) {
bitcoinKit = BitcoinKit(withWords: words, walletId: "bitcoin-wallet-id")
bitcoinKit.delegate = self
}
}
extension Manager: BitcoinCoreDelegate {
func transactionsUpdated(inserted: [TransactionInfo], updated: [TransactionInfo]) {
}
func transactionsDeleted(hashes: [String]) {
}
func balanceUpdated(balance: Int) {
}
func lastBlockInfoUpdated(lastBlockInfo: BlockInfo) {
}
public func kitStateUpdated(state: BitcoinCore.KitState) {
// BitcoinCore.KitState can be one of 3 following states:
// .synced
// .syncing(progress: Double)
// .notSynced
//
// These states can be used to implement progress bar, etc
}
}
Listener events are run in a dedicated background thread. It can be switched to main thread by setting the delegateQueue
property to DispatchQueue.main
bitcoinKit.delegateQueue = DispatchQueue.main
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'
use_frameworks!
target '<Your Target Name>' do
pod 'BitcoinCore.swift'
pod 'BitcoinKit.swift'
pod 'BitcoinCashKit.swift'
pod 'DashKit.swift'
end
Then, run the following command:
$ pod install
All features of the library are used in example project. It can be referred as a starting point for usage of the library.
The BitcoinKit-iOS
toolkit is open source and available under the terms of the MIT License.
在iOS开发过程中,我们经常需要保存用户名和密码等敏感信息,于此同时呢 iOS的安全机制给了我们一个保存敏感信息的途径 就是钥匙串 我们可以将用户名密码保存在系统的钥匙串中 而且利用这种方式保存的用户名密码相对来说时间也较长也比较安全 钥匙串里面的内容不会因为APP的安装和卸载而丢失里面的数据 即使重装APP钥匙串里面的信息依然可以随时取用 大大方便了用户 使用之前我们需要导入Security.
.h #import <Foundation/Foundation.h> #import <Security/Security.h> @interface CHKeyChain : NSObject + (void)save:(NSString *)service data:(id)data; + (id)load:(NSString *)service; + (void)dele
BitcoinKit Bitcoin and Bitcoin Cash(ABC) SPV wallet toolkit implemented in Kotlin. This is a full implementation of SPV node including wallet creation/restore, syncronzation with network, send/receive
Bitcoin (比特币)是点对点(peer-to-peer)基于网络的匿名数字货币。点对点(peer-to-peer)的意思是指没有中央权威控制货币 的汇款通道。相反,这些货币转帐的任务是由网络节点进行的集体管理。匿名就意味着交易各方可以隐藏自己的真实身份。优势: 无需信托中间人,能够方便的进行互联网上的汇款。 第三方不能够控制或者阻止您的交易。 Bitcoin 交易几乎免费, 而信用卡的网上在
Bitcoin-Qt 是使用 Qt 开发的比特币客户端,目前该项目已经成为比特币官方的客户端,合并到比特币项目中,不再单独立项。
Bitcoin ETL Join Telegram Group Install Bitcoin ETL: pip install bitcoin-etl Export blocks and transactions (Schema, Reference): > bitcoinetl export_blocks_and_transactions --start-block 0 --end-block
BITCOIN WALLET Welcome to Bitcoin Wallet, a standalone Bitcoin payment app for your Android device! This project contains several sub-projects: wallet:The Android app itself. This is probably what you
Feature-rich toolkit for making Bitcoin and Lightning applications on the JVM. For a complete guide on how to get started with Bitcoin-S, see our website at Bitcoin-S.org. Contents What is bitcoin-s?