ethers.js
ethers.js copied to clipboard
Ethers create random freezes main thread in react native
Ethers Version
6.8.1
Search Terms
No response
Describe the Problem
When calling ethers.Wallet.createRandom() in react native the ui freezes probavly because the calculations are done in the main thread. how can we solve that ?
React native version
"react-native": "^0.72.4",
Code Snippet
No response
Contract ABI
No response
Errors
No response
Environment
No response
Environment (Other)
No response
There are features added in v6 specifically to address this by shimming out the JavaScript functions for native implementations. I plan to get a package up that makes all these shims available, but any help would be appreciates.
For example, the expensive part of .createRandom() is likely the sha2-512 operation, so you can use: ethers.sha512.register((data) => { return nativeImplementation(data); } where nativeImplementation is a function you provide that calls a JNI (or such) implementation.