无法将Dapp部署到rinkeby

时间:2019-12-18 17:15:04

标签: ethereum solidity truffle

问题 当我尝试使用命令

部署到rinkeby时
truffle migrate --reset --network rinkeby

运行上述命令后,得到以下结果。实际错误进一步降低。非常欢迎提出任何指向我可以解决此问题的建议。

        Starting migrations...
======================
> Network name:    'rinkeby'
> Network id:      4
> Block gas limit: 0x98705c


1_initial_migration.js
======================
   Replacing 'Migrations'
   ----------------------
   > transaction hash:    0x14bdcbb929d5c81530f4af1468ab3e84bdfb72a2369fdbff5c9645c06735aa9d
   > Blocks: 1            Seconds: 17
   > contract address:    0x88401B02262B3d4C3A3B1BfCeDf00e0531fa0d38
   > block number:        5642911
   > block timestamp:     1576782953
   > account:             0x6b4119610F218E058C332c59Ed6b26DA8c045a87
   > balance:             18.64313901
   > gas used:            225237
   > gas price:           10 gwei
   > value sent:          0 ETH
   > total cost:          0.00225237 ETH

   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.00225237 ETH

2_deploy_contracts.js
=====================
   Replacing 'StarNotary'
   ----------------------
   > transaction hash:    0xa4cda00d28cdc34ddb462b8c779c88378003bccfa50c5956cbd3bc587a2f9ffc
   > Blocks: 0            Seconds: 9
   > contract address:    0xC35D4d083E9F16B8253Ec26c9a64afB0af22c3c3
   > block number:        5642913
   > block timestamp:     1576782983
   > account:             0x6b4119610F218E058C332c59Ed6b26DA8c045a87
   > balance:             18.61937604
   > gas used:            2333934
   > gas price:           10 gwei
   > value sent:          0 ETH
   > total cost:          0.02333934 ETH

   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.02333934 ETH
Summary
=======
> Total deployments:   2
> Final cost:          0.02559171 ETH

truffle(develop)> Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\web3-core-helpers\src\errors.js:42:16)
    at XMLHttpRequest.request.onreadystatechange (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\web3-providers-http\src\index.js:92:32)
    at XMLHttpRequestEventTarget.dispatchEvent (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\xhr2-cookies\xml-http-request-event-target.ts:44:13)
    at XMLHttpRequest._setReadyState (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\xhr2-cookies\xml-http-request.ts:219:8)
    at XMLHttpRequest._onHttpRequestError (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\xhr2-cookies\xml-http-request.ts:379:8)
    at ClientRequest.<anonymous> (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\xhr2-cookies\xml-http-request.ts:266:37)
    at ClientRequest.emit (events.js:198:13)
    at ClientRequest.EventEmitter.emit (domain.js:448:20)
    at TLSSocket.socketErrorListener (_http_client.js:392:9)
    at TLSSocket.emit (events.js:198:13)
    at TLSSocket.EventEmitter.emit (domain.js:448:20)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

这是我的truffle.js配置,请我是以太坊区块链上DApp开发的新手。

const HDWalletProvider = require("@truffle/hdwallet-provider");
const infuraKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  networks: {
    development: {
     host: "127.0.0.1",     // Localhost (default: none)
     port: 9545,            // Standard Ethereum port (default: none)
     network_id: "*",       // Any network (default: none)
    },
    rinkeby: {
      provider: () => new HDWalletProvider(mnemonic, `https://rinkeby.infura.io/v3/${infuraKey}`),
      network_id: 4,       // rinkeby's id
      gas: 4500000,        // rinkeby has a lower block limit than mainnet
      gasPrice: 10000000000
    }, 
  }
}

请如何解决此问题。 谢谢

1 个答案:

答案 0 :(得分:1)

truffle-hdwallet-provider已过时。它已移至trufflesuit/truffle的monorepo下。您应该使用该版本。您可以通过

安装它
$ npm install @truffle/hdwallet-provider

在truffle-config.js中

const HDWalletProvider = require("@truffle/hdwallet-provider");