Skip to main content
The Spark React Native SDK provides React Native support for building Bitcoin wallet applications on iOS and Android. This guide covers installation and basic setup. Before getting started, ensure you have a React Native development environment set up with Xcode and iOS Simulator (run pod install after installing dependencies) for iOS development, or Android Studio and Android SDK for Android development.

Getting Started

To get started, follow the steps below.
1

Install SDK

Install the Spark SDK packages using your package manager of choice.
npm install @buildonspark/spark-sdk
2

Add Required Polyfills

Install the required polyfills for React Native compatibility.
npm install react-native-get-random-values @azure/core-asynciterator-polyfill buffer text-encoding
3

Setup Wallet

Create a wallet instance that will be used to interact with the Spark network.
wallet.jsx
import { SparkWallet } from "@buildonspark/spark-sdk";

export const initializeWallet = async () => {
  const { wallet, mnemonic } = await SparkWallet.initialize({
    mnemonicOrSeed: "optional-mnemonic-or-seed",
    accountNumber: "optional-number",
    options: {
      network: "REGTEST" // or "MAINNET"
    }
  });

  console.log("Wallet initialized successfully:", mnemonic);
  return wallet;
};
4

Start Building

That’s it—you can now start using the Spark React Native SDK.
App.jsx
import { SparkWallet } from "@buildonspark/spark-sdk";

export function WalletInfo() {
  const [wallet, setWallet] = useState(null);
  const [loading, setLoading] = useState(false);

  const createWallet = async () => {
    setLoading(true);
    try {
      const { wallet, mnemonic } = await SparkWallet.initialize({
        options: { network: "REGTEST" }
      });
      setWallet(wallet);
      console.log("Mnemonic:", mnemonic);
    } catch (error) {
      console.error("Failed to create wallet:", error);
    } finally {
      setLoading(false);
    }
  };

  return (
    <View>
      <Text>Wallet Information</Text>
      {loading ? (
        <Text>Loading...</Text>
      ) : wallet ? (
        <View>
          <Text>Address: {wallet.getAddress()}</Text>
          <Text>Balance: {wallet.getBalance()} sats</Text>
        </View>
      ) : (
        <Button title="Create Wallet" onPress={createWallet} />
      )}
    </View>
  );
}

Initialize a Wallet

A wallet requires either a mnemonic or raw seed for initialization. The initialize() function accepts both. If no input is given, it will auto-generate a mnemonic and return it.
// Initialize a new wallet instance
const { wallet, mnemonic } = await SparkWallet.initialize({
  mnemonicOrSeed: "optional-mnemonic-or-seed",
  accountNumber: "optional-number",
  options: {
    network: "REGTEST" // or "MAINNET"
  }
});

console.log("Wallet initialized successfully:", mnemonic);

Mnemonic Phrases

A mnemonic is a human-readable encoding of your wallet’s seed. It’s a 12- or 24-word phrase from the BIP-39 wordlist, used to derive the cryptographic keys that control your wallet.

React Native Current Status

The React Native SDK is currently in beta with active development. We’re shipping improvements weekly. Current Limitations:
  • Uses polling for updates instead of real-time streams
  • Some edge cases may have rough handling