Skip to content

bitcoindevkit/bdk-dart

bdk-dart

Dart bindings for the Bitcoin Dev Kit (BDK) wallet library. The repo contains the sources for generating UniFFI-based bindings (lib/bdk.dart) and the libbdk_dart_ffi native library, so Dart and Flutter apps can work with descriptor-based wallets, key management utilities, and blockchain backends from BDK.

Repository layout

Path Purpose
native/ Rust sources and uniffi-dart build scripts and configs wrapping the underlying bdk-ffi crate to be used by the Dart build hook.
lib/ Dart bindings (bdk.dart) generated by UniFFI-Dart.
example/ Standalone Dart example to showcase, test and play with the bindings.
test/ Offline/construction/persistence tests (not full integration tests).
bdk_demo/ Flutter sample app you can point at mobile targets once the bindings are built.
scripts/generate_bindings.sh Helper used to rebuild the native library and regenerate the Dart bindings.

Prerequisites

To use this package you need:

  • Dart SDK >= 3.10 or newer (see pubspec.yaml).
  • Rust toolchain with cargo and the native targets you intend to build. You can install Rust via rustup.
  • Flutter SDK if you plan to use the package in a Flutter app or run the Flutter demo.

Add to your project

Via git:

dependencies:
  bdk_dart:
    git:
      url: https://github.com/bitcoindevkit/bdk-dart.git
      ref: main # or specific tag

Via pub.dev:

COMING SOON: Currently not published on pub.dev yet.

Usage

Check out the example in example/main.dart for a walkthrough of how to use the bindings to:

  1. Create a new mnemonic and derive BIP84 descriptors.
  2. Instantiate a wallet backed by the in-memory persister.
  3. Reveal addresses and persist staged changes.
  4. Optionally sync with Electrum over TLS.

Run it with:

dart run example/main.dart

If you have the Rust toolchain installed, the native library will be automatically built by Dart's Native Assets system. As a user of the package, you don't need to worry about building the native library or bindings yourself. Only if you want to contribute to the bindings or modify the native code yourself, you can follow the instructions in development below. The first build can take several minutes depending on your machine and network (subsequent builds are faster). We currently pin git dependencies to specific commits for reproducibility (including bdk-ffi until the next release is cut); the plan is to move to release tags as upstream ships them.

Development

Generating bindings

  1. Modify the native Rust code and configuration files in native/ as needed.

  2. Run the bindings generator script:

    bash ./scripts/generate_bindings.sh

Testing

Once you have generated lib/bdk.dart and the native library locally you can execute the Dart test suite, which covers wallet creation, persistence, offline behavior, and descriptor APIs:

dart test

License

The Rust crate and generated bindings are dual-licensed under MIT or Apache 2.0 per the license = "MIT OR Apache-2.0" entry in native/Cargo.toml. You may choose either license when using the library in your project.

About

No description, website, or topics provided.

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5