Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# bdk-dart

Dart bindings for the [Bitcoin Dev Kit (BDK)](https://bitcoindevkit.org/) wallet library.
The repo packages the generated UniFFI bindings (`lib/bdk.dart`) together with the
compiled `libbdkffi` native library so Dart and Flutter apps can work with descriptor-based
Comment on lines +4 to +5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are gitignored though I thought? or maybe we just need to reword?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, you’re right, the generated bindings and native libs are gitignored.
I can reword this section to clarify that the repo provides the sources + UniFFI config, and that the generated artifacts are produced locally rather than checked in

wallets, key management utilities, and blockchain backends from BDK.

## Repository layout

| Path | Purpose |
| ---- | ------- |
| `bdk-ffi/` | Rust sources and build scripts for the underlying `bdk-ffi` crate. |
| `lib/` | Generated Dart bindings (`bdk.dart`) produced by UniFFI-Dart. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implies lib/ contains checked-in bindings which I'm not sure is the case

| `examples/` | Standalone Dart examples that exercise common workflows. |
| `test/` | Integration-style tests that cover wallet creation, persistence, and networking. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we change this to something like Dart unit tests for wallet construction, offline behavior, persistence or something since we only have offline tests at the moment?

| `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 build the bindings locally you need:

- Dart SDK 3.2 or newer (see `pubspec.yaml`).
- Rust toolchain with `cargo` and the native targets you intend to build.
- `clang`/`lld` (or equivalent platform toolchain) for producing the shared library.
- Flutter (optional) if you plan to run `bdk_demo`.

Make sure submodules are cloned because the Rust crate lives in `bdk-ffi/`:

```bash
git clone --recurse-submodules https://github.com/bitcoindevkit/bdk-dart.git
cd bdk-dart
```

## Installation

1. Install dependencies:
```bash
dart pub get
```
2. Generate the Dart bindings and native binary:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add something like (macOS or Linux host required) here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it’s a good idea since it directly addresses the reviewer’s question about the host requirements for generating bindings

```bash
./scripts/generate_bindings.sh
```
The script builds `bdk-ffi`, runs the local `uniffi-bindgen` wrapper, and drops the
resulting `libbdkffi.*` alongside the freshly generated `lib/bdk.dart`.
3. Make sure the produced library is discoverable at runtime. For CLI usage you can export
`LD_LIBRARY_PATH`/`DYLD_LIBRARY_PATH` or keep the binary in the same directory as your
Dart entrypoint.

## Usage

After generating the bindings you can run the examples or consume the package from your
own project. For instance, the `examples/network_example.dart` walkthrough shows how 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:

```bash
dart run examples/network_example.dart
```

When embedding in Flutter, add a path or git dependency on this package and ensure the
native library is bundled per target platform (e.g., via `flutter_rust_bridge`-style
build steps or platform-specific build scripts).

## Testing

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

```bash
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 `Cargo.toml`. You may choose either license when
using the library in your project.
Loading