Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LtbLightning/bdk-flutter
Bitcoin Development Kit - Flutter Package
https://github.com/LtbLightning/bdk-flutter
Last synced: 4 days ago
JSON representation
Bitcoin Development Kit - Flutter Package
- Host: GitHub
- URL: https://github.com/LtbLightning/bdk-flutter
- Owner: LtbLightning
- License: mit
- Created: 2022-03-26T14:48:05.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-19T18:30:54.000Z (4 months ago)
- Last Synced: 2024-08-02T17:29:39.647Z (3 months ago)
- Language: Dart
- Size: 708 MB
- Stars: 60
- Watchers: 11
- Forks: 27
- Open Issues: 34
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-bdk - bdk-flutter on GitHub
README
### Bdk Flutter
A Flutter library for the [Bitcoin Development Kit](https://bitcoindevkit.org/).
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:
```dart
dependencies:
bdk_flutter: ^0.31.2
```### Examples
### Create a Wallet & sync the balance of a descriptor
```dart
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
```dart
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
```dart
import 'package:bdk_flutter/bdk_flutter.dart';final bdkWallet = .....
// ....
final txBuilder = TxBuilder();
final address = await Address.fromString(s: "mv4rnyY3Su5gjcDNzbMLKBQkBicCtHUtFB", network: Network.testnet);final script = await address.scriptPubkey();
final feeRate = await blockchain.estimateFee(target: 25);final (psbt, transactionDetails) = await txBuilder.feeRate( feeRate.satPerVb )
.addRecipient( script, 2000 )
.finish( bdkWallet );final serializedPsbt = await 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.
```dart
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 =
await 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 =
await 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 =
await bdkWallet.getAddress(addressIndex: const AddressIndex.increase());
final internalAddress =
await bdkWallet.getInternalAddress(addressIndex: const AddressIndex.increase());```
### API Documentation
The latest API documentation is available [here](https://pub.dev/documentation/bdk_flutter/latest/bdk_flutter/bdk_flutter-library.html)
### Example Projects
- **\*BDK Flutter Demo App:** The [BDK Flutter Demo App](https://github.com/LtbLightning/bdk-flutter-quickstart)
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#116938Thanks for taking a look!