ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

Ethers create random freezes main thread in react native

Open valavanisleonidas opened this issue 1 year ago • 1 comments

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

valavanisleonidas avatar Feb 29 '24 18:02 valavanisleonidas

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.

ricmoo avatar Apr 10 '24 00:04 ricmoo