Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help needed in React Native Integration #1927

Open
theDevSoham opened this issue May 30, 2023 · 8 comments
Open

Help needed in React Native Integration #1927

theDevSoham opened this issue May 30, 2023 · 8 comments

Comments

@theDevSoham
Copy link

Hi, I'm trying to integrate [email protected] in react-native project. The errors I'm facing are pretty much understandable. For eg:

  1. ReferenceError: Property 'Buffer' doesn't exist, js engine: hermes . OR
  2. fs cannot be found in node modules etc.

It seems some core node modules are not available in react-native. Possible solutions I tried:

  1. Installing rn-nodeify and shimming the libraries not present in react native (Problem: some modules like react-native-udp uses compile method in it's gradle file which is deprecated.)
  2. Using alternative libraries like react-native-bitcoinjs-lib or rn-bitcoinjs-lib (Problem: They require rn-nodeify which recurs the previous problem)
  3. Following this thread: https://gist.github.com/coreyphillips/4d45160fed016417a5f583f179c2cbdb (Problem: It's showing process not found although process is inbuilt in react native or rather it extends something like NodeProcess still it's showing error. Couldn't really understand what's the issue).

Please let me know if it's possible to suggest a workaround because the client needs this library only. Thanks a lot in advance.

@ChrisCho-H
Copy link
Contributor

ChrisCho-H commented Jun 20, 2023

  1. install buffer and react-native-get-random-values dependency
  2. make file global.js in root directory(where index.js is in)
import {Buffer} from 'buffer';
import 'react-native-get-random-values';

global.crypto.getRandomValues;
global.Buffer = Buffer;
  1. import global.js in index.js
/**
 * @format
 */
import './global.js';
import { AppRegistry } from 'react-native';
import App from './App';

AppRegistry.registerComponent(appName, () => App);

I don't think fs error coming from this library

@ChrisCho-H
Copy link
Contributor

ChrisCho-H commented Jun 20, 2023

And u can refer this if cipher-base error happens if u install stream
#1865

@ChrisCho-H
Copy link
Contributor

ChrisCho-H commented Jun 20, 2023

if u install tiny-secp256k1 as well, u need to use version with 1.0.0~1.1.6 unless u r gonna integrate WASM in mobile.

@ChrisCho-H
Copy link
Contributor

ChrisCho-H commented Jun 20, 2023

And u probably need to install events as well

@theDevSoham
Copy link
Author

Thanks @ChrisCho-H . Yes this fixes the issue for me. By the way created a template repo for integrating bitcoinjs-lib and ethers into react native v0.71.x so that others don't have to go through this hassle already 🙂. Feel free to check this out:
https://github.com/theDevSoham/react_native_crypto_wallet_template

@junderw
Copy link
Member

junderw commented Jul 22, 2023

https://www.npmjs.com/package/@bitcoin-js/tiny-secp256k1-asmjs

Released asmjs version of tiny-secp256k1.

Also, @bitcoinerlab/secp256k1 also implements the same interface and is slightly faster (but it uses native JS BigInt, so if your build environment can't handle that, you can't use it)

@divyangkhatri
Copy link

Thanks @ChrisCho-H . Yes this fixes the issue for me. By the way created a template repo for integrating bitcoinjs-lib and ethers into react native v0.71.x so that others don't have to go through this hassle already 🙂. Feel free to check this out: https://github.com/theDevSoham/react_native_crypto_wallet_template

It is working fine.

@theDevSoham
Copy link
Author

@divyangkhatri happy to help 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants