1

我们web3用于连接到 rinkeby 测试以太坊网络。通过 localhost 使用以下 web3 命令通过 geth 执行此操作时:

var web3 = new Web3('http://localhost:8545');

我们没有收到任何错误。我们使用这个命令来启动 geth:

geth --rinkeby --rpc --rpcapi="personal,eth,network,web3,net" --ipcpath "~/Library/Ethereum/geth.ipc"

但是,当我们尝试直接使用 rinkeby 测试网络时:

var web3 = new Web3('https://rinkeby.infura.io/');

我们得到这个错误:

Error: Invalid JSON RPC response: ""
   at Object.InvalidResponse (errors.js:42)
   at XMLHttpRequest.request.onreadystatechange (index.js:73)
   at XMLHttpRequest.dispatchEvent (event-target.js:172)
   at XMLHttpRequest.setReadyState (XMLHttpRequest.js:546)
   at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:387)
   at XMLHttpRequest.js:493
   at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
   at MessageQueue.__callFunction (MessageQueue.js:353)
   at MessageQueue.js:118
   at MessageQueue.__guardSafe (MessageQueue.js:316)

大多数操作在两个网络上都有效,但.send()直接连接到 rinkeby 网络时调用失败。

我们认为这是身份验证的问题,因为其他命令成功但不执行事务。但是,我们尝试使用 HDWalletProvider 并且我们通过 geth 创建的帐户都没有助记符。

任何建议或故障排除步骤将不胜感激。谢谢

4

1 回答 1

1

交易必须签署。当您通过本地 geth 节点发送交易时,它知道与您发送的地址对应的私钥,因此它可以为您签署交易(一旦您解锁帐户)。

像 Infura 这样的公共节点(幸运的是!)不知道您的私钥,因此它无法为您签署交易。您需要在本地对其进行签名,然后使用sendSignedTransaction.

于 2018-04-03T06:54:29.993 回答