React Native BLE (hd-ble-sdk)

Demo: React Native / Expo example โ†’ react-native-demo

This guide shows how to use the pure React Native BLE stack with @onekeyfe/hd-ble-sdk and @onekeyfe/hd-transport-react-native. No WebView or low-level adapter is required. The chain API usage stays the same as in Quick Start.

Install

We recommend installing the RN-native dependencies at the app layer so that autolinking includes the native modules in your Dev Client build:

npm i @onekeyfe/hd-ble-sdk @onekeyfe/hd-transport-react-native \
      @onekeyfe/react-native-ble-utils react-native-ble-plx \
      buffer process react-native-get-random-values react-native-url-polyfill

In your app entry (e.g., index.js or App.tsx):

// Polyfills (adjust to your project needs)
import 'react-native-get-random-values';
import 'react-native-url-polyfill/auto';
// @ts-ignore
global.Buffer = global.Buffer || require('buffer').Buffer;
// @ts-ignore
global.process = global.process || require('process');

// Register RN transport side-effects before SDK init
import '@onekeyfe/hd-transport-react-native';

import HardwareSDK from '@onekeyfe/hd-ble-sdk';

Android setup

Add permissions in AndroidManifest.xml (Android 12+):

At runtime, request BLUETOOTH_SCAN and BLUETOOTH_CONNECT (and location on Android 12+). Ensure the system Location toggle is ON.

iOS setup

Add to Info.plist:

  • NSBluetoothAlwaysUsageDescription (required)

  • Optionally NSBluetoothPeripheralUsageDescription for older iOS versions

  • If your app uses the camera (e.g. QR scanning), add NSCameraUsageDescription

If using Expo, you can declare these in app.json under expo.ios.infoPlist and expo.android.permissions.

Metro config (polyfills & exports)

Map Node core APIs and enable package exports for subpath imports like @noble/hashes/blake2b:

Build Dev Client (real devices)

Expo Go does not include your native BLE modules. Build a Dev Client:

Initialize and subscribe to events

Discover devices and identify device_id

Persist connectId and deviceId (most chain APIs require both).

First call example (BTC address)

Tips

  • Always subscribe early to UI_EVENT so PIN/Passphrase/confirmations do not stall requests. See Config Event.

  • Keep BLE permissions in sync with the OS version. Test on physical devices.

  • For additional examples, check: react-native-demo

Continue

Last updated

Was this helpful?