首页 > 解决方案 > 来自 infura 测试网的错误在 react-native 应用程序中为空

问题描述

我用它从一个连接到infura rospten react-native mobile app

const url = 'https://ropsten.infura.io/v3/xxx';
this.web3 = new Web3(new Web3.providers.HttpProvider(url))

当我打电话给合同时,我得到:

Error: Invalid JSON RPC response: ""]

为什么错误为空?

使用相同的方法连接到本地 ganache,它就可以工作了。

是因为授权还是网络配置?

标签: react-nativeethereum

解决方案


您需要/v3从 URL 中删除该部分

兑换

const url = 'https://ropsten.infura.io/v3/xxx';

至:

const url = 'https://ropsten.infura.io/xxx';

此外,您是否在连接到 infura 之前签署了交易。在提出任何交易请求之前,您需要为地址签署交易。您可以使用HD-wallet-provider并使用在您创建帐户期间提供给您的助记符。


推荐阅读