Search categories, packages and repositories

Package detailsv0.31.3

bdk_flutter

A Flutter library for the Bitcoin Development Kit(bdk) (https://bitcoindevkit.org/)

AndroidiOSmacOS
30-day downloads
589
Likes
36
Pub points
140

Install package

flutter pub add bdk_flutter

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

bdk_flutter is a Flutter library that integrates the Bitcoin Development Kit (bdk) into Flutter applications, enabling developers to build secure, native Bitcoin wallets with full control over key management, transaction creation, and blockchain interaction. It provides a bridge to bdk's robust Rust-based backend, offering features like HD wallet support, PSBT handling, and blockchain synchronization. Designed for Web3, crypto, and blockchain apps, it empowers developers to create lightweight, privacy-focused Bitcoin solutions across Android, iOS, and macOS platforms.

Use cases

  • Building Bitcoin wallets in Flutter apps
  • Creating PSBTs for multi-signature transactions
  • Integrating Bitcoin blockchain sync
  • Managing HD wallets with BIP39 and BIP44
  • Enabling offline signing workflows

Key features

  • Native integration with Bitcoin Development Kit
  • Support for HD wallets and BIP standards
  • PSBT creation and signing capabilities
  • Cross-platform compatibility (Android, iOS, macOS)
  • Secure key management and wallet operations

Suitable for

  • Flutter developers building Bitcoin wallets
  • Web3 projects requiring Bitcoin functionality
  • Apps needing offline transaction signing
  • Developers using Rust-based bdk backend
  • Crypto-native mobile applications

Considerations

  • Requires understanding of Bitcoin fundamentals
  • Limited documentation compared to mature libraries
  • Potential performance overhead on low-end devices
  • Depends on native platform setup for bdk
  • May require additional configuration for production deployment

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Bdk Flutter

BDK is released under the MIT license. Docs Current pub package version. Issues Stars Forks Demo App

A Flutter library for the Bitcoin Development Kit. The bdk library aims to be the core building block for Bitcoin Applications of any kind.

Requirements
  • Flutter : 3.0 or higher
  • Android minSdkVersion. : API 23 or higher.
  • Deployment target : iOS 12.0 or greater.
How to Use

To use the bdk_flutter package in your project, add it as a dependency in your project's pubspec.yaml:

dependencies:
  bdk_flutter: ^0.31.3
Examples
Create a Wallet & sync the balance of a descriptor
import 'package:bdk_flutter/bdk_flutter.dart';

// ....

final mnemonic = await Mnemonic.create(WordCount.words12);
final descriptorSecretKey = await DescriptorSecretKey.create( network: Network.testnet,
                                                              mnemonic: mnemonic );
final externalDescriptor = await Descriptor.newBip44( secretKey: descriptorSecretKey,
                                                      network: Network.testnet,
                                                      keychain: KeychainKind.externalChain );
final internalDescriptor = await Descriptor.newBip44( secretKey: descriptorSecretKey,
                                                      network: Network.testnet,
                                                      keychain: KeyChainKind.internalChain );
final blockchain = await Blockchain.create( config: BlockchainConfig.electrum(
                                                                        config: ElectrumConfig(
                                                                            stopGap: 10,
                                                                            timeout: 5,
                                                                            retry: 5,
                                                                            url: "ssl://electrum.blockstream.info:60002" )));
final wallet = await Wallet.create( descriptor: externalDescriptor,
                                    changeDescriptor: internalDescriptor,
                                    network: Network.testnet,
                                    databaseConfig: const DatabaseConfig.memory() );
final _ = await wallet.sync( blockchain );
Create a public wallet descriptor
import 'package:bdk_flutter/bdk_flutter.dart';

// ....

final mnemonic = await Mnemonic.create(WordCount.words12);
final descriptorSecretKey = await DescriptorSecretKey.create( network: Network.testnet,
                                                              mnemonic: mnemonic );
final externalDescriptor = await Descriptor.newBip44( secretKey: descriptorSecretKey,
                                                      network: Network.testnet,
                                                      keychain: KeychainKind.externalChain  );
final externalPublicDescriptor = await Descriptor.create( descriptor: externalDescriptor.toString(),
                                                    network: Network.testnet);
Get the transaction details
import 'package:bdk_flutter/bdk_flutter.dart';

final bdkWallet = .....

// ....

final txBuilder  = TxBuilder();
final address = await Address.fromString(s: "mv4rnyY3Su5gjcDNzbMLKBQkBicCtHUtFB", network: Network.testnet);

final script =  address.scriptPubkey();
final feeRate = await blockchain.estimateFee(target: 25);

final (psbt, transactionDetails) = await txBuilder.feeRate( feeRate.satPerVb )
                                       .addRecipient( script, 2000 )
                                       .finish( bdkWallet );

final serializedPsbt =  psbt.jsonSerialize();
final jsonObject = json.decode(serializedPsbt);
final outputs = jsonObject['unsigned_tx']['output'] as List;
final inputs = jsonObject['inputs'][0]['non_witness_utxo']['output'] as List;

debugPrint("=========Inputs=====");
    for (var e in inputs) {
      debugPrint("amount: ${e['value']}");
      debugPrint("script_pubkey: ${e['script_pubkey']}");
    }

debugPrint("=========Outputs=====");
    for (var e in outputs) {
      debugPrint("amount: ${e['value']}");
      debugPrint("script_pubkey: ${e['script_pubkey']}");
    }

Create an internal and extarnal wallet descriptors from derivation path.
import 'package:bdk_flutter/bdk_flutter.dart';


final mnemonic = await Mnemonic.create(WordCount.words12);
final descriptorSecretKey = await DescriptorSecretKey.create(
        network: Network.testnet, mnemonic: mnemonic);

// create external descriptor
final derivationPath = await DerivationPath.create(path: "m/44h/1h/0h/0");
final descriptorPrivateKey =
         descriptorSecretKey.derive(derivationPath);
final Descriptor descriptorPrivate = await Descriptor.create(
      descriptor: "pkh(${descriptorPrivateKey.toString()})",
      network: Network.testnet,
    );

// create internal descriptor
final derivationPathInt =
        await DerivationPath.create(path: "m/44h/1h/0h/1");
final descriptorPrivateKeyInt =
         descriptorSecretKey.derive(derivationPathInt);
final Descriptor descriptorPrivateInt = await Descriptor.create(
      descriptor: "pkh(${descriptorPrivateKeyInt.toString()})",
      network: Network.testnet,
    );

final bdkWallet = await Wallet.create(
      descriptor: descriptorPrivate,
      changeDescriptor: descriptorPrivateInt,
      network: Network.testnet,
      databaseConfig: const DatabaseConfig.memory(),
    );

final address =
        bdkWallet.getAddress(addressIndex: const AddressIndex.increase());
final internalAddress =
        bdkWallet.getInternalAddress(addressIndex: const AddressIndex.increase());

API Documentation

The latest API documentation is available here

Example Projects
  • *BDK Flutter Demo App: The BDK Flutter Demo App is a simple bitcoin app built in flutter to serve as a reference app to demonstrate bdk-flutter api usage.
References:
  • Setting up a local Esplora instance for testing: https://bitcoin.stackexchange.com/questions/116937/how-do-i-setup-an-esplora-instance-for-local-testing/116938#116938

Thanks for taking a look!

Categories

Dependencies

Dependency list 6 items

Source repository

Projects using this package