Wallet

class Wallet(    descriptor: String,     changeDescriptor: String,     network: Network,     databaseConfig: DatabaseConfig)

A Bitcoin wallet. The Wallet acts as a way of coherently interfacing with output descriptors and related transactions. Its main components are:

  1. Output descriptors from which it can derive addresses.

  2. A Database where it tracks transactions and utxos related to the descriptors.

  3. Signers that can contribute signatures to addresses instantiated from the descriptors.

Samples


fun main() { 
   //sampleStart 
   val externalDescriptor = "wpkh(tprv8hwWMmPE4BVNxGdVt3HhEERZhondQvodUY7Ajyseyhudr4WabJqWKWLr4Wi2r26CDaNCQhhxEfVULesmhEfZYyBXdE/84h/1h/0h/0/*)"
val internalDescriptor = "wpkh(tprv8hwWMmPE4BVNxGdVt3HhEERZhondQvodUY7Ajyseyhudr4WabJqWKWLr4Wi2r26CDaNCQhhxEfVULesmhEfZYyBXdE/84h/1h/0h/1/*)"
val sqliteDatabaseConfig = DatabaseConfig.Sqlite(SqliteDbConfiguration("bdk-sqlite"))

val wallet = BdkWallet(
    descriptor = externalDescriptor,
    changeDescriptor = internalDescriptor,
    network = Network.TESTNET,
    databaseConfig = sqliteDatabaseConfig,
) 
   //sampleEnd
}

Parameters

descriptor

The main (or "external") descriptor.

changeDescriptor

The change (or "internal") descriptor.

network

The network to act on.

databaseConfig

The database configuration.

Constructors

Link copied to clipboard
fun Wallet(    descriptor: String,     changeDescriptor: String,     network: Network,     databaseConfig: DatabaseConfig)

Create a BDK wallet.

Functions

Link copied to clipboard
fun getAddress(addressIndex: AddressIndex): AddressInfo

Return a derived address using the external descriptor, see AddressIndex for available address index selection strategies. If none of the keys in the descriptor are derivable (i.e. the descriptor does not end with a * character) then the same address will always be returned for any AddressIndex.

Link copied to clipboard
fun getBalance(): ULong

Return the balance, meaning the sum of this wallet’s unspent outputs’ values. Note that this method only operates on the internal database, which first needs to be Wallet.sync manually.

Link copied to clipboard
fun listTransactions(): List<TransactionDetails>

Return the list of transactions made and received by the wallet. Note that this method only operate on the internal database, which first needs to be Wallet.sync manually.

Link copied to clipboard
fun listUnspent(): List<LocalUtxo>

Return the list of unspent outputs of this wallet. Note that this method only operates on the internal database, which first needs to be Wallet.sync manually.

Link copied to clipboard
fun network(): Network

Get the Bitcoin network the wallet is using.

Link copied to clipboard
fun sign(psbt: PartiallySignedBitcoinTransaction): Boolean

Sign a transaction with all the wallet’s signers.

Link copied to clipboard
fun sync(blockchain: Blockchain, progress: Progress?)

Sync the internal database with the blockchain.