无法在没有远程调试器的情况下调用 web3.eth.accounts.create() 反应本机应用程序

Unable to call web3.eth.accounts.create() without remote debugger on react native app

我正在使用 react-native 构建一个 android 钱包并尝试使用 web3.eth.accounts.create() 创建一个帐户。这适用于启用的 react-native 远程调试器。但是,当我在关闭调试器的情况下处理相同的代码时,它会停止工作。

这是我的package.json

"cryptico": "^1.0.2",
"native-base": "2.8.0",
"node-libs-browser": "2.1.0",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-firebase": "^5.2.0",
"react-native-gesture-handler": "^1.0.12",
"react-native-scripts": "1.14.0",
"react-navigation": "^3.0.9",
"socket.io-client": "2.0.4",
"web3": "1.0.0-beta.34"

我自己在 React Native 中使用 web3 时遇到问题,所以我切换到 ethers.js 。 它在 RN 内部运行得更好,它几乎可以为您提供所需的一切。

我通过使用 ethers.js 创建新的以太坊钱包修复了它。

// this is specifically for react-native
import 'ethers/dist/shims';
import {ethers} from 'ethers';
// to create a ethereum wallet
let randomWallet = ethers.Wallet.createRandom();

Web3.js对react-native来说真的很麻烦
在这里阅读更多: https://docs.ethers.io/ethers.js/html/cookbook-react.html#

这是专门为 react-native 设计的指南