搜索插件、代码仓与 APP 分类

插件详情v0.31.3

bdk_flutter

一个用于比特币开发工具包(bdk)的 Flutter 库(https://bitcoindevkit.org/)

AndroidiOSmacOS
近 30 天下载
589
喜欢数
36
Pub 分数
140

安装插件

flutter pub add bdk_flutter

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

bdk_flutter 是一个 Flutter 库,将比特币开发工具包(bdk)集成到 Flutter 应用中,使开发者能够构建安全的原生比特币钱包,完全掌控密钥管理、交易创建和区块链交互。它提供了一个与 bdk 强大的基于 Rust 的后端通信的桥梁,支持功能如 HD 钱包、PSBT 处理和区块链同步。专为 Web3、加密货币和区块链应用设计,该库可帮助开发者在 Android、iOS 和 macOS 平台上创建轻量级、注重隐私的比特币解决方案。

适合场景

  • 在Flutter应用中构建比特币钱包
  • 创建多签名交易的PSBT
  • 集成比特币区块链同步
  • 使用BIP39和BIP44管理HD钱包
  • 启用离线签名工作流

主要特点

  • 与比特币开发工具包的原生集成
  • 对 HD 钱包和 BIP 标准的支持
  • PSBT 创建和签名功能
  • 跨平台兼容性(Android、iOS、macOS)
  • 安全的密钥管理和钱包操作

适合对象

  • Flutter 开发人员构建比特币钱包
  • 需要比特币功能的Web3项目
  • 需要离线交易签名的应用
  • 使用基于 Rust 的 bdk 后端的开发者
  • 原生加密货币移动应用

使用建议

  • 需要了解比特币基础知识
  • 与成熟库相比,文档有限
  • 低端设备上可能存在性能开销
  • 依赖于原生平台设置的 bdk
  • 可能需要额外配置才能用于生产部署

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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!

所属分类

依赖

依赖清单 6 项

源码仓库

使用此插件的项目