Back to Blog
blockchain
6 min read

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.

Tang Yetong
Tang Yetong
Full Stack Developer and former Data Analyst Intern at Fivetran with a background in government digital services and blockchain technology.

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. You can use the Padawan Wallet and dev-kit 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 :

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 :

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 :

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 :

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 :

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

Tags

BDK-Kotlin
Bitcoin
Testnet
Wallet Creation
Tang Yetong

Tang Yetong

Full Stack Developer and former Data Analyst Intern at Fivetran with a background in government digital services and blockchain technology.

Related Articles

Featured
5 mins

How to contribute to Padawan Wallet

blockchain

A quick summary of what the Padawan Wallet is, why it exists and how you can contribute to it!

Bitcoin
Open Source
BDK-Kotlin
+1
Read Article: How to contribute to Padawan Wallet
Featured
8 mins

Summer of Bitcoin 2022

blockchain

This is the last week of the Summer of Bitcoin (SoB) 2022 internship and what a journey it has been.

SoB
Internship
Bitcoin
+1
Read Article: Summer of Bitcoin 2022
4 mins

Bumping RBF Enabled Transaction Fees using BDK-Kotlin

blockchain

A quick guide on how to use the BDK-Kotlin 0.8.0 library to bump Replace-By-Fee(RBF) enabled transaction fees.

BDK-Kotlin
Bitcoin
RBF
+1
Read Article: Bumping RBF Enabled Transaction Fees using BDK-Kotlin