react-native - 在 React Native 应用程序上没有远程调试器时无法调用 web3.eth.accounts.create()

标签 react-native ethereum web3js

我正在使用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/

相关文章:

blockchain - 实体事件如何存储在以太坊区 block 链上?

react-native - 如何在 react-native 中使用 navigator 组件显示导航栏

android - 如果恢复初始生命周期状态,则需要设置 Activity

swift - 如何从 Swift 应用程序与部署在区 block 链上的智能合约进行交互

ethereum - Solidity 中的重入 hack 不再适用于 pragma ^0.8.0

node.js - npm install web3 安装失败 : undefined ls-remote

node.js - 为什么我的异步等待不等待我的 web3.js sendRawTransaction?

node.js - 如何从 Nodejs 文件调用 Web3js 函数

jenkins - Yarn 忽略代理设置

android - 尝试运行android项目时出现问题