Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: null is not an object (evaluating 'RNRandomBytes.seed') React Native

am developing a mobile app using React native, which involves an interaction with web3.js and Problem is RN does not support core Node.js modules, so I had to install

npm i --save react-native-crypto

npm i --save react-native-randombytes

react-native link react-native-randombytes

npm i --save-dev rn-nodeify@latest

./node_modules/.bin/rn-nodeify --hack --install

and now I face this error whenever I try to use crypto or web3.js enter image description here

Any clue what's the issue or maybe how to resolve it ?

like image 570
Mohamed Ahmed Avatar asked Jul 04 '26 21:07

Mohamed Ahmed


1 Answers

It seems like installation problem of react-native-randombytes library.

Did not you think about using the different, more popular library that offers same API?

npm says that react-native-randombytes has 19,294 weekly downloads. Another library called react-native-get-random-values (with cca 481,572 weekly downloads) is almost guaranteed to work (as it is recommended to use in combination with packages like - uuid ). The npm link for this library is here.

By taking look at the source code of both libraries that were mentioned above, both use the same Android API, backed by SecureRandom, so I would expect that there are similarities on iOS too.

react-native-get-random-values (link here ):

@ReactMethod(isBlockingSynchronousMethod = true)
  public String getRandomBase64(int byteLength) throws NoSuchAlgorithmException {
    byte[] data = new byte[byteLength];
    SecureRandom random = new SecureRandom();

    random.nextBytes(data);

    return Base64.encodeToString(data, Base64.NO_WRAP);
  }

react-native-randombytes library - link here:

@ReactMethod
  public void randomBytes(int size, Callback success) {
    success.invoke(null, getRandomBytes(size));
  }

private String getRandomBytes(int size) {
    SecureRandom sr = new SecureRandom();
    byte[] output = new byte[size];
    sr.nextBytes(output);
    return Base64.encodeToString(output, Base64.NO_WRAP);
  }


like image 177
Stefan Majiros Avatar answered Jul 06 '26 11:07

Stefan Majiros



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!