bitcoinjs-lib
bitcoinjs-lib copied to clipboard
Help needed in React Native Integration
Hi, I'm trying to integrate [email protected] in react-native project. The errors I'm facing are pretty much understandable. For eg:
ReferenceError: Property 'Buffer' doesn't exist, js engine: hermes. ORfs cannot be found in node modulesetc.
It seems some core node modules are not available in react-native. Possible solutions I tried:
- Installing
rn-nodeifyand shimming the libraries not present in react native (Problem: some modules likereact-native-udp uses compile method in it's gradle file which is deprecated.) - Using alternative libraries like
react-native-bitcoinjs-liborrn-bitcoinjs-lib(Problem: They require rn-nodeify which recurs the previous problem) - 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.
- install
bufferandreact-native-get-random-valuesdependency - 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;
- 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
And u can refer this if cipher-base error happens if u install stream
https://github.com/bitcoinjs/bitcoinjs-lib/issues/1865
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.
And u probably need to install events as well
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
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)
Thanks @ChrisCho-H . Yes this fixes the issue for me. By the way created a template repo for integrating
bitcoinjs-libandethersinto 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.
@divyangkhatri happy to help 😊