All Projects → horizontalsystems → bitcoin-kit-android

horizontalsystems / bitcoin-kit-android

Licence: MIT license
Comprehensive Bitcoin development library for iOS, implemented on Swift. SPV wallet implementation for Bitcoin, Bitcoin Cash, Litecoin and Dash blockchains. Fully compliant with existing standards and BIPs.

Programming Languages

kotlin
9241 projects
C++
36643 projects - #6 most used programming language
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to bitcoin-kit-android

Bitcoin Kit Ios
Full Bitcoin library for iOS, implemented on Swift. SPV wallet implementation for Bitcoin, Bitcoin Cash and Dash blockchains.
Stars: ✭ 134 (+31.37%)
Mutual labels:  decentralized, p2p, dash, btc, bitcoin-wallet
Crypto-Wallet
Open source SHA-512 loginless bitcoin wallet
Stars: ✭ 24 (-76.47%)
Mutual labels:  decentralized, btc, bitcoin-wallet, litecoin
Unstoppable Wallet Android
A secure and decentralized Bitcoin and other cryptocurrency wallet for Android phones. Supports Bitcoin, Ethereum, EOS, Binance Chain, Bitcoin Cash, DASH, ...
Stars: ✭ 165 (+61.76%)
Mutual labels:  decentralized, p2p, btc
gdax bot
gdax_bot - Micro dollar cost averaging for crypto
Stars: ✭ 57 (-44.12%)
Mutual labels:  btc, litecoin, bch
MoneroMixer
The easiest way to use Monero to anonymously exchange and properly mix XMR, BTC, LTC, ETH, BCH, & 100+ other coins on Tails OS or Whonix.
Stars: ✭ 57 (-44.12%)
Mutual labels:  dash, litecoin, bitcoin-cash
Essentia-iOS
All in One Blockchain solution
Stars: ✭ 50 (-50.98%)
Mutual labels:  dash, litecoin, bitcoin-cash
Unstoppable Wallet Ios
A secure and decentralized Bitcoin and other cryptocurrency wallet for iPhone. Supports Bitcoin, Ethereum, EOS, Binance Chain, Bitcoin Cash, DASH, ...
Stars: ✭ 180 (+76.47%)
Mutual labels:  decentralized, p2p, btc
wallet-address-validator
Useful library for validation of Bitcoin, Litecoin, Ethereum and other cryptocoin addresses
Stars: ✭ 240 (+135.29%)
Mutual labels:  dash, litecoin, bitcoin-cash
p2p-cdn-sdk-android
Free p2p cdn android github sdk to reduce video streaming costs of live and on demand video using webrtc by upto 90% and improve scalability by 6x - 🚀 Vadootv 🚀
Stars: ✭ 39 (-61.76%)
Mutual labels:  p2p, dash
moonshine
Moonshine is a homebrewed, open-source, non-custodial, Bitcoin wallet for iOS & Android.
Stars: ✭ 56 (-45.1%)
Mutual labels:  bitcoin-wallet, litecoin
pop
Run a point-of-presence within Myel, the community powered content delivery network.
Stars: ✭ 28 (-72.55%)
Mutual labels:  decentralized, p2p
Satellite-Legacy
Satellite gives you peace of mind with end-to-end encryption without sacrificing quality. Stream in 4k, chat in 500kbs+, share 10GB files.
Stars: ✭ 46 (-54.9%)
Mutual labels:  decentralized, p2p
MugglePay
Make Crypto Payment Easy 让数字货币支付更简单
Stars: ✭ 176 (+72.55%)
Mutual labels:  btc, bch
swarm-peer-server
🖧 A network swarm for creating secure P2P connections over BitTorrent DHT, DNS, and mDNS.
Stars: ✭ 41 (-59.8%)
Mutual labels:  decentralized, p2p
cryptowallet-cli
CW is a crypto wallet generator CLI tool for a lot of blockchains: Bitcoin, Ethereum, Binance Smart Chain and many others
Stars: ✭ 45 (-55.88%)
Mutual labels:  btc, litecoin
evian
www.balletcrypto.org/
Stars: ✭ 21 (-79.41%)
Mutual labels:  dash, bch
bitforce
A tools brute force BTC
Stars: ✭ 24 (-76.47%)
Mutual labels:  btc, bitcoin-wallet
namecoin-core
Namecoin full node + wallet based on the current Bitcoin Core codebase.
Stars: ✭ 425 (+316.67%)
Mutual labels:  decentralized, p2p
field-manual
The Offical User's Guide to OrbitDB
Stars: ✭ 178 (+74.51%)
Mutual labels:  decentralized, p2p
Horizon
A ZeroNet search engine
Stars: ✭ 15 (-85.29%)
Mutual labels:  decentralized, p2p

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 transactions, and more.

Features

  • Full SPV implementation for fast mobile performance
  • Send/Receive Legacy transactions (P2PKH, P2PK, P2SH)
  • Send/Receive Segwit transactions (P2WPKH)
  • Send/Receive Segwit transactions compatible with legacy wallets (P2WPKH-SH)
  • Fee calculation depending on wether sender pays the fee or receiver
  • Encoding/Decoding of base58, bech32, cashaddr addresses
  • BIP32 hierarchical deterministic wallets implementation.
  • BIP39 mnemonic code for generating deterministic keys.
  • BIP44 multi-account hierarchy for deterministic wallets.
  • BIP21 URI schemes, which include payment address, amount, label and other params
  • Real-time fee rates

Usage

Initialization

BitcoinKit requires you to provide mnemonic phrase when it is initialized:

val words = listOf("skill", ..., "century")

Bitcoin

val context: Context = App.instance
val walletId = 'MyWalletId'
val bitcoinKit = BitcoinKit(context, walletId, words, BitcoinKit.NetworkType.MainNet)

Bitcoin Cash

val bitCashKit = BitcoinCashKit(context, walletId, words, BitcoinCashKit.NetworkType.MainNet)

Both networks can be configured to work in MainNet or TestNet

Additional parameters:
  • peerSize: Can be configured for number of peers to be connected (default: 10)
  • confirmationsThreshold: Minimum number of confirmations required for an unspent output in incoming transaction to be spent (default: 6)

Starting and Stopping

BitcoinKit requires to be started with start command, but does not need to be stopped. It will be in synced state as long as it is possible:

bitcoinKit.start()

Clearing data from device

BitcoinKit uses internal database for storing data fetched from blockchain. The clear command can be used to stop and clean all stored data:

bitcoinKit.clear()

Getting wallet data

BitcoinKit holds all kinds of data obtained from and needed for working with blockchain network

Current Balance

Balance is provided in Satoshi:

bitcoinKit.balance
// 2937096768

Receive Address

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()
// mfu3iYeZuh18uuN4CrGYz34HSMynZBgZyg

Transactions

You can get all your transactions as follows:

bitcoinKit.transactions

TransactionInfo(
    transactionHash=baede6420b4b2869cba87d768a7b4e2eef2a9899149f24c5c3d3ff66b8ad1405,
    from=[TransactionAddress(address=my1ysPMHdeQD6kwnimipbvFrr5NRHDvNgz, mine=false)],
    to=[
        TransactionAddress(address=moyrWfrks5EsHLb2hqUr8nUnC9q9DYXMtK, mine=true),
        TransactionAddress(address=2NDk1BuuKnbVqDAMVgGr6xurnctfaQVxFoN, mine=false)
    ],
    amount=32500000,
    blockHeight=1316822,
    timestamp=1527595501
  ),
  TransactionInfo(
    transactionHash=60ff9d204c17e0e71a1fd2d3f60b1bada5573857691d30d7518311057cc75720, 
    from=[
        TransactionAddress(address=mtmnfGuW4e5RbC64r3vx2qFhS3pobf57Ty, mine=false)
    ], 
    to=[
        TransactionAddress(address=mt59yxihUxy117RPQuEVQ7QSRuHJnRT4fG, mine=true), 
        TransactionAddress(address=2NAn7FBKvMFWteiHKSDDBudUP4vPwiBfVkr, mine=false)
    ], 
    amount=16250000, 
    blockHeight=1316823, 
    timestamp=1527595771
)
...

Sending new transaction

In order to create new transaction, call send(address: String, value: Int, senderPay: Boolean = true) method on BitcoinKit

  • senderPay: parameter defines who pays the fee
bitcoinKit.send("mrjQyzbX9SiJxRC2mQhT4LvxFEmt9KEeRY", 1000000)

This function 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.

Validating transaction before send

One can validate address and fee by using following methods:

bitcoinKit.validate(address = "mrjQyzbX9SiJxRC2mQhT4LvxFEmt9KEeRY")
bitcoinKit.fee(value = 1000000, address = "mrjQyzbX9SiJxRC2mQhT4LvxFEmt9KEeRY", senderPay: true)
  • senderPay: parameter defines who pays the fee

Parsing BIP21 URI

You can use parsePaymentAddress method to parse a BIP21 URI:

bitcoinKit.parsePaymentAddress("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=50&label=Luke-Jr&message=Donation%20for%20project%20xyz")

BitcoinPaymentData(
  address=175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W, 
  version=null, 
  amount=50.0,
  label=Luke-Jr,
  message=Donation for project xyz,
  parameters=null
)

Subscribing to BitcoinKit data

BitcoinKit provides with data like transactions, blocks, balance, kitState in real-time. BitcoinKit.Listener interface must be implemented and set to BitcoinKit instance to receive that data.

class MainViewModel : ViewModel(), BitcoinKit.Listener {

    private var bitcoinKit: BitcoinKit
    ...
    
    init {
        bitcoinKit = BitcoinKit(words, BitcoinKit.NetworkType.TestNet)
        bitcoinKit.listener = this
    }
    
    override fun onTransactionsUpdate(bitcoinKit: BitcoinKit, inserted: List<TransactionInfo>, updated: List<TransactionInfo>) {
        // do something with transactions
    }

    override fun onTransactionsDelete(hashes: List<String>) {
        // do something with transactions
    }

    override fun onBalanceUpdate(bitcoinKit: BitcoinKit, balance: Long) {
        // do something with balance
    }

    override fun onLastBlockInfoUpdate(bitcoinKit: BitcoinKit, blockInfo: BlockInfo) {
        // do something with blockInfo
    }

    override fun onKitStateUpdate(bitcoinKit: BitcoinKit, state: KitState) {
        // These states can be used to implement progress bar, etc
        when (state) {
            is KitState.Synced -> {

            }
            is KitState.Syncing -> {
                // val progress: Double = state.progress
            }
            is KitState.NotSynced -> {
                
            }
        }
    }
}

Listener events are run in a dedicated background thread. It can be switched to main thread by setting the listenerExecutor property to MainThreadExecutor()

bitcoinKit.listenerExecutor = MainThreadExecutor()

Prerequisites

  • JDK >= 1.8
  • Android 6 (minSdkVersion 23) or greater

Installation

Add the JitPack to module build.gradle

repositories {
    maven { url 'https://jitpack.io' }
}

Add the following dependency to your build.gradle file:

dependencies {
    implementation 'com.github.horizontalsystems:bitcoin-kit-android:master-SNAPSHOT'
}

Example App

All features of the library are used in example project. It can be referred as a starting point for usage of the library.

Dependencies

  • HDWalletKit - HD Wallet related features, mnemonic phrase

Contributing

Contributing

License

The BitcoinKit is open source and available under the terms of the MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].