我正在使用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"
最佳答案
我通过使用 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设计的指南
关于react-native - 在 React Native 应用程序上没有远程调试器时无法调用 web3.eth.accounts.create(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54420690/