LtbLightning / bdk-rn

Bitcoin Development Kit - React Native Module
MIT License
50 stars 15 forks source link

Expo with BDK-RN #79

Closed Psycarlo closed 5 months ago

Psycarlo commented 5 months ago

Hi. I am trying to make bdk-rn work with expo. I can't even generate a 12 word mnemonic. 👇🏼

Replication steps:

Note: I am using Node v18.19.0, npm v10.5.0, windows machine

  1. Init expo
npx create-expo-app --template

Choose template: Blank (TypeScript)

"dependencies": {
    "expo": "~50.0.14",
    "expo-status-bar": "~1.11.1",
    "react": "18.2.0",
    "react-native": "0.73.6"
  },
  1. Install bdk-rn
npm i --save bdk-rn
  1. Update App.tsx
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View, Button } from "react-native";
import { Mnemonic } from "bdk-rn";
import { WordCount } from "bdk-rn/lib/lib/enums";
import { useState } from "react";

export default function App() {
  const [mnemonic, setMnemonic] = useState("");

  const handleClick = async () => {
    const mnemonic = await new Mnemonic().create(WordCount.WORDS12);
    setMnemonic(mnemonic.asString());
  };

  return (
    <View style={styles.container}>
      <Text>Open up App.tsx to start working on your app!</Text>
      <Button title="Generate" onPress={handleClick} />
      <Text>Test: {mnemonic}</Text>
      <StatusBar style="auto" />
    </View>
  );
}

...
  1. Run the app
npm start
  1. Use Expo Go to run the app (running on my iPhone 12)

Now I get the following error:

Possible unhandled promise rejection | TypeError: Cannot read property 'generateSeedFromWordCount' of null

cc @BitcoinZavior

BitcoinZavior commented 5 months ago

There are 2 different workflows used by Expo to run Apps.

  1. Managed workflow: where we can only use services/modules provided by Expo e.g npx expo start
  2. Bare workflow: 3rd party libraries can also be used. “bdk-rn” is 3rd party for expo. e.g npx expo run:ios

bdk-rn just like any other RN module will work with Bare Workflow but not with Managed Workflow