Helium React Native SDK
npm install @helium/react-native-sdkThe Helium React Native SDK is a collection of modules that can be used by a React Native
application to interact with Hotspots and the Helium Blockchain.
It has first class support for Typescript.
For usage, refer to the Helium Maker Starter App which utilizes this
SDK to build out the base features needed to add Hotspots to the Helium Blockchain.
Along with this you may find the following Helium documentation useful:
- Helium Developer Site
- Helium Blockchain API
- Helium JS
``sh`
yarn add @helium/react-native-sdkor
npm install @helium/react-native-sdk
Please browse the documentation for more information.
You can import the different modules such as Account,
Location,
HotspotBleManager,
heliumHttpClient,
and AddGateway to get started.
`ts
import { Account, Location, AddGateway } from '@helium/react-native-sdk';
// example usage of Account.createKeypair
const { keypairRaw, address, mnemonic } = await Account.createKeypair();
`
There is an example app included with this SDK. It's intended for reference only and currently does not build on the Apple M1 processor.
A practical use of this SDK can be seen here Helium Maker Starter App
Use the {@link HotspotBleManager} to interact with a Hotspot via bluetooth.
`ts
import { HotspotBleProvider, useHotspotBle } from '@helium/react-native-sdk';
// some examples of the functions you may want to use
const { startScan, stopScan, connect, scannedDevices } = useHotspotBle();
`
In order to get started with the {@link HotspotBleManager} you must first wrap your root app component in a
{@link HotspotBleProvider}.
For example:
`tsx
import React from 'react';
import { HotspotBleProvider } from '@helium/react-native-sdk';
const App = () => (
);
`
You are now ready to use the {@link HotspotBleManager} throughout your application.
You can use the {@link HotspotBleManager} to {@link startScan}, {@link stopScan}, and read information from {@link scannedDevices}. Check
out the {@link Device} docs for more info on scanned devices.
For a full working example see the example app.
`tsx
import React, { useEffect } from 'react';
import { useHotspotBle } from '@helium/react-native-sdk';
const { startScan, stopScan, scannedDevices } = useHotspotBle();
useEffect(() => {
// you would probably want to call this on a button click, we scan right away
startScan((error) => {
if (error) {
console.error(error);
}
});
}, []);
useEffect(() => {
// you would probably want to call this on a button click, but we stop after 10 seconds
setTimeout(stopScan, 10000);
}, []);
const ScanComponent = () =>
`
After scanning, you can connect to {@link scannedDevices} by calling {@link connect}.
`ts
import { useHotspotBle } from '@helium/react-native-sdk';
const { connect, scannedDevices } = useHotspotBle();
connect(scannedDevices[0]);
``
Once {@link connect} has been called you can use the other {@link HotspotBleManager} to interact with a connected {@link Device}. For
example, you may want to call {@link getDiagnosticInfo} to read the hotspot's diagnostic information or {@link readWifiNetworks}
to display available wifi networks the hotspot can see and then {@link setWifi} to set a network.
Visit the example app for full examples of
Wifi Setup,
WifiSettings, or
Diagnostics.
See the contributing guide to learn how to contribute to the repository and the development workflow.