Skip to content

Bitcoin Dev Kit — React Native

React Native language bindings for the Bitcoin Development Kit.

Installation

npm install bdk-rn

The package ships prebuilt native libraries for iOS and Android, so you do not need a Rust toolchain, and nothing is compiled or downloaded at install time.

Prereleases (betas and release candidates) are published under the next tag instead of latest, so npm install bdk-rn never picks one up. To try the most recent one, run npm install bdk-rn@next.

Requirements

  • The React Native New Architecture, which is on by default since React Native 0.76. bdk-rn is a TurboModule and does not work with the old architecture.
  • An app with native projects you build yourself. bdk-rn contains native code, so it does not run in Expo Go. With Expo, use a development build.

iOS

Install the pods after adding the package:

cd ios && pod install

Supported targets are arm64 devices and arm64 simulators (Apple Silicon Macs).

Android

Supported ABIs are arm64-v8a (devices) and x86_64 (emulators). 32-bit ABIs (armeabi-v7a and x86) are not supported.

New React Native apps build all four ABIs by default. The 32-bit builds would not contain bdk-rn and would crash on a 32-bit-only device, so restrict your app to the supported ABIs in android/gradle.properties:

reactNativeArchitectures=arm64-v8a,x86_64

bdk-rn's small C++ bridge is compiled as part of your app's build, using the NDK and CMake your React Native app already uses.

Usage

import {
  Mnemonic,
  WordCount,
  DescriptorSecretKey,
  Descriptor,
  KeychainKind,
  Network,
  NetworkKind,
  Persister,
  Wallet,
} from 'bdk-rn';

const mnemonic = new Mnemonic(WordCount.Words12);
const secretKey = new DescriptorSecretKey(NetworkKind.Test, mnemonic, undefined);
const descriptor = Descriptor.newBip86(secretKey, KeychainKind.External, NetworkKind.Test);

const wallet = Wallet.createSingle(descriptor, Network.Signet, Persister.newInMemory());
const addressInfo = wallet.revealNextAddress(KeychainKind.External);

The example apps show more of the API.

About This Repository

The code in this repository is mostly comprised of:

  • Build tools
  • CI and release workflows
  • Tests
  • Docs

The core Rust code that is exposed to the React Native language bindings actually resides in the bdk-ffi repository. This repo pulls it in as a submodule and applies patches to it so that sync methods on the Electrum and Esplora clients become async when used on the JS side.

To build the library from source, for example to work on bdk-rn itself, see Build. For more on how the bindings are generated, see the uniffi-bindgen-react-native documentation.