An open API service indexing awesome lists of open source software.

https://github.com/bitcoindevkit/bdk-dart


https://github.com/bitcoindevkit/bdk-dart

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

          

# bdk-dart

Dart bindings for the [Bitcoin Dev Kit (BDK)](https://bitcoindevkit.org/) 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](https://rustup.rs/).
- Flutter SDK if you plan to use the package in a Flutter app or run the [Flutter demo](bdk_demo/).

## Supported targets

See [SUPPORTED_TARGETS.md](SUPPORTED_TARGETS.md) for the current platform/architecture matrix and support status.

### Add to your project

**Via git:**

```yaml
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:

```bash
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](#development) below.
The first build can take several minutes depending on your machine and network (subsequent builds are faster).
We pin git dependencies to immutable refs for reproducibility. `bdk-ffi` tracks the upstream release tag, while `uniffi-dart` remains pinned to a commit until tagged releases are available upstream.

## Development

For release operations, see [PUBDEV_RELEASE_CHECKLIST.md](PUBDEV_RELEASE_CHECKLIST.md).

### Generating bindings

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

2. Run the bindings generator script:

```bash
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:

```bash
dart test
```

### Integration tests

Integration tests are in `test/integration/` and are env-gated by default.
Without the env vars below, integration tests are skipped.

Run integration tests with:

```bash
BDK_DART_RUN_INTEGRATION=1 \
BDK_DART_ELECTRUM_URL=ssl://electrum.blockstream.info:60002 \
BDK_DART_ESPLORA_URL=https://blockstream.info/testnet/api \
dart test test/integration
```

Optional env vars:

- `BDK_DART_ELECTRUM_SOCKS5`
- `BDK_DART_ESPLORA_PROXY`

## 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.