# Getting Started with BDK-KOTLIN
## What is BDK?
The bdk library aims to be the core building block for Bitcoin wallets of any kind.
* It uses Miniscript to support descriptors with generalized conditions. This exact same library can be used to build single-sig wallets, multisigs, timelocked contracts and more.
* It supports multiple blockchain backends and databases, allowing developers to choose exactly what's right for their projects.
* It's built to be cross-platform: the core logic works on desktop, mobile, and even WebAssembly.
* It's very easy to extend: developers can implement customized logic for blockchain backends, databases, signers, coin selection, and more, without having to fork and modify this library.
## Alright... then what is BDK-KOTLIN?
This project builds .jar and .aar packages for the jvm and android platforms that provide Kotlin language bindings for the bdk library. The Kotlin language bindings are created by the bdk-ffi project which is included as a git submodule of this repository.
## How do I use BDK-KOTLIN with my android project?
Ah well! That really simple. Just follow along.
First we will need to add the following line to our gradle dependencies, and then sync your project.
```
repositories {
mavenCentral()
}
dependencies {
...
implementation 'org.bitcoindevkit:bdk-android:<version>'
...
}
```
Latest verson v0.7.0 (At the time of writing this note)
## What can I do with this Library?
So many things!
Alright, actually answering now.
* Create & Broadcast Transaction
* Create Wallet using Descriptors
* Create ExtendedKeys
* Create BumpFee Transaction
Here is an example:
```
import org.bitcoindevkit.*
// ...
val externalDescriptor = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
val internalDescriptor = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"
val databaseConfig = DatabaseConfig.Memory
val blockchainConfig =
BlockchainConfig.Electrum(
ElectrumConfig("ssl://electrum.blockstream.info:60002", null, 5u, null, 10u)
)
val wallet = Wallet(externalDescriptor, internalDescriptor, Network.TESTNET, databaseConfig, blockchainConfig)
val newAddress = wallet.getNewAddress()
```
## Setup BDK-KOTLIN in your machine
[Should have git & rust installed on your machine]
Start by cloning the repository using `git clone`
```
git clone https://github.com/bitcoindevkit/bdk-kotlin
```
BDK-KOTLIN uses the submodule BDK-FFI and you are required to update the submodule using
```
git submodule update --init
```
Install required targets using
```
rustup target add x86_64-apple-darwin aarch64-apple-darwin
rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
```
Setup $ANDROID_SDK_ROOT and $ANDROID_NDK_ROOT path variables (which are required by the build tool), for example (NDK major version 21 is required)
```
export ANDROID_SDK_ROOT=~/Android/sdk
export ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/21.<NDK_VERSION>
```
To build the library (JVM or Android)
```
# build JVM library
./gradlew :jvm:buildJvmLib
# build Android library
./gradlew :android:buildAndroidLib
```
## How to publish
You can publish the generated library to local maven using the commands
```
./gradlew :jvm:publishToMavenLocal
./gradlew :android:publishToMavenLocal
```
In case you don't have gpg keys, you can exclude the `signMavenPublication` subtask.
```
./gradlew :jvm:publishToMavenLocal --exclude-task signMavenPublication
./gradlew :android:publishToMavenLocal --exclude-task signMavenPublication
```
## Where to find the local library
Path to local libraries for both JVM and Android
```
Unix/MacOS
~/.m2/repository/org/bitcoindevkit/bdk-android/0.6.0-SNAPSHOT
~/.m2/repository/org/bitcoindevkit/bdk-jvm/0.6.0-SNAPSHOT
Windows
C:\Users\{username}\.m2\repository\org\bitcoindevkit\bdk-android\0.6.0-SNAPSHOT
C:\Users\{username}\.m2\repository\org\bitcoindevkit\bdk-jvm\0.6.0-SNAPSHOT
```
## Use local library (bdk-android) in your android project
All you have to do in project you want to use locally published library, is add in project root build.gradle file mavenLocal() in repository list, so it looks like that:
```
allprojects {
repositories {
mavenLocal()
jcenter()
...
```
How it works: Gradle while building your project will look for dependencies first in local Maven repository, then if it won’t find requested dependency it will try JCenter etc.
You can sync the gradle and use the methors provided in the bdk-android library.
## Contributing to BDK-KOTLIN
This repository (BDK-KOTLIN) uses the submodule BDK-FFI to generate the Kotlin code required to generate to library for android and jvm. So, in order to add some functionality to the BDK-KOTLIN you are required to contribute to the BDK-FFI project.
## BDK-FFI
This repository is the Native language bindings for BDK. The languages that are supported at the moment are Kotlin, Swift and Python.
Tool use to crate these bindings is the [uniffi-rs](https://mozilla.github.io/uniffi-rs/).
To add some functionality you will have to update these files according to the documentation provided in [here](https://mozilla.github.io/uniffi-rs/).
```
../bdk-ffi/src/lib.rs
../bdk-ffi/src/bdk.udl
```
On completing the change you can test out of the changes made are working by `cargo build` and also by adding test for what you have added and check if the changes works as expected.