# Creating a Testnet wallet using BDK-Kotlin

> A quick guide on how to use the BDK-Kotlin 0.7.0 library to create a Bitcoin testnet wallet for your own testing purposes.

By Tang Yetong. Published June 25, 2022. 6 min read. Category: blockchain. Tags: BDK-Kotlin, Bitcoin, Testnet, Wallet Creation.
Read it with the interactive demos: https://tangyetong.com/blog/creating-testnet-wallet-bdk-kotlin

A quick guide on how to use the [`BDK-Kotlin 0.7.0`](https://github.com/bitcoindevkit/bdk-kotlin) library to create a Bitcoin testnet wallet for your own testing purposes. 
You can use the [`Padawan Wallet`](https://github.com/thunderbiscuit/padawan-wallet) and [`dev-kit`](https://github.com/thunderbiscuit/devkit-wallet/tree/simple-wallet) open-source projects as reference. 

## Wallet Creation

To create a wallet using `BDK-Kotlin` is really simple, with the `Wallet` class being really intuitive to use. To create a testnet wallet you will just have to call `Wallet()` with all the necessary information for a wallet to be created. As an example this is a snippet of the code used in `Padawan Wallet` :

```kotlin
val wallet: Wallet = Wallet(descriptor = descriptor, network = Network.TESTNET, databaseConfig = databaseConfig)
```

The variables required to build a valid wallet are `descriptor`, `network` and `databaseConfig`. We will quickly go through each one since they are simple to understand.

`descriptor: String` : This is the wallet descriptor that tells the wallet how to generate addresses. 

`network: Network` : This is the network you want to connect to. In our case we want `Network.TESTNET` for testing purposes. 

`databaseConfig: DatabaseConfig` : This is the database configuration for the wallet to store its data.

Finally you will have to call `Wallet()` with all the necessary parameters. This returns a `Wallet` object.

## Wallet Recovery

To recover a wallet using `BDK-Kotlin` is also really simple. You will just have to call `Wallet()` with the mnemonic phrase instead of the descriptor. As an example this is a snippet of the code used in `Padawan Wallet` :

```kotlin
val wallet: Wallet = Wallet(mnemonic = mnemonic, network = Network.TESTNET, databaseConfig = databaseConfig)
```

The variables required to recover a wallet are `mnemonic`, `network` and `databaseConfig`. We will quickly go through each one since they are simple to understand.

`mnemonic: String` : This is the mnemonic phrase that was used to create the wallet. 

`network: Network` : This is the network you want to connect to. In our case we want `Network.TESTNET` for testing purposes. 

`databaseConfig: DatabaseConfig` : This is the database configuration for the wallet to store its data.

Finally you will have to call `Wallet()` with all the necessary parameters. This returns a `Wallet` object.

## ExtendedKeyInfo

To get the `ExtendedKeyInfo` object from the wallet you will just have to call `getExtendedKeyInfo()` on the wallet object. As an example this is a snippet of the code used in `Padawan Wallet` :

```kotlin
val extendedKeyInfo: ExtendedKeyInfo = wallet.getExtendedKeyInfo()
```

The `ExtendedKeyInfo` object contains all the information about the wallet, including the descriptor, network, and other metadata.

## Descriptor

To get the descriptor from the `ExtendedKeyInfo` object you will just have to call `descriptor` on the `ExtendedKeyInfo` object. As an example this is a snippet of the code used in `Padawan Wallet` :

```kotlin
val descriptor: String = extendedKeyInfo.descriptor
```

The descriptor is a string that tells the wallet how to generate addresses. It is used to create the wallet and can be used to recover the wallet.

## Mnemonic

To get the mnemonic from the `ExtendedKeyInfo` object you will just have to call `mnemonic` on the `ExtendedKeyInfo` object. As an example this is a snippet of the code used in `Padawan Wallet` :

```kotlin
val mnemonic: String = extendedKeyInfo.mnemonic
```

The mnemonic is a string that is used to recover the wallet. It is generated when the wallet is created and can be used to recover the wallet.

## Summary

To create a testnet wallet using `BDK-Kotlin` you will just have to call `Wallet()` with the descriptor, network, and database configuration. To recover a wallet you will just have to call `Wallet()` with the mnemonic phrase, network, and database configuration. The `ExtendedKeyInfo` object contains all the information about the wallet, including the descriptor and mnemonic.

Remember that to recover a wallet you just need the [descriptor](https://bitcoindevkit.org/descriptors/) to let the scripts know how to generate the addresses, hence after retrieving the `ExtendedKeyInfo` object it is easy to see that the rest of the code remains the same.
