搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案