首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:无效的JSON响应\ ropsten.infura

错误:无效的JSON响应\ ropsten.infura
EN

Ethereum用户
提问于 2019-07-19 00:36:41
回答 1查看 546关注 0票数 0

我正在尝试将我的合同部署到ropsten测试网络,但是我得到了这个错误。

消息错误:

代码语言:javascript
复制
C:\Users\acer\test>truffle migrate --reset --network ropsten
Using network 'ropsten'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0xf9d9daf3c904e239bc27fd70a51916e1dd954238215f631e7f341e1270fa55ab
Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (C:\Users\acer\test\node_modules\web3\lib\web3\errors.js:35:16)
    at XMLHttpRequest.request.onreadystatechange (C:\Users\acer\test\node_modules\web3\lib\web3\httpprovider.js:115:32)
    at XMLHttpRequest.dispatchEvent (C:\Users\acer\test\node_modules\xhr2\lib\xhr2.js:76:20)
    at XMLHttpRequest._setReadyState (C:\Users\acer\test\node_modules\xhr2\lib\xhr2.js:422:14)
    at XMLHttpRequest._onHttpRequestError (C:\Users\acer\test\node_modules\xhr2\lib\xhr2.js:669:14)
    at ClientRequest.request.on (C:\Users\acer\test\node_modules\xhr2\lib\xhr2.js:499:23)
    at ClientRequest.emit (events.js:182:13)
    at TLSSocket.socketErrorListener (_http_client.js:391:9)
    at TLSSocket.emit (events.js:182:13)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  Migrations: 0x116940816fb03041b4fc9018dffdef346fe0932b
Saving artifacts...
Running migration: 2_migration.js
  Replacing DinarCoin...
  ... 0x8b1ddbc08abb3561be6df6148a7a5cf9006e1e6ae520dd9e8a67713ed6af33cd
  DinarCoin: 0xeb43d979ec0d3d004c5d50c202e2cbec02edf2e1
Saving artifacts...
  Deploying DinarCrowdsale...
  ... 0x949fff0717b07829fd62f5df0fb9f21ad1ed2d4b9665704c75aab206fcf49921
Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (C:\Users\acer\test\node_modules\web3\lib\web3\errors.js:35:16)

请问我如何解决这个问题?提前谢谢你。

EN

回答 1

Ethereum用户

发布于 2019-07-20 15:05:47

@SanjaySB,

Tru浮-config.js文件:

代码语言:javascript
复制
require('babel-register');
require('babel-polyfill');
require('dotenv').config();
const HDWalletProvider = require('truffle-hdwallet-provider');

module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*', // eslint-disable-line camelcase
    },
    ganache: {
      host: 'localhost',
      port: 8545,
      network_id: '*', // eslint-disable-line camelcase
    },
    ropsten: {
      provider: function() {
        return new HDWalletProvider(
          process.env.MNEMONIC,
          `https://ropsten.infura.io/v3/9ffa4f404f6c47bf9dd98937dc4dee36`
        )
      },
      gas: 5000000,
      gasPrice: 25000000000,
      network_id: 3, 
      skipDryRun: true  
    },
    rinkeby: {
        provider: function() { 
         return new HDWalletProvider(process.env.MNEMONIC, "https://rinkeby.infura.io/v3/9ffa4f404f6c47bf9dd98937dc4dee36");
        },
        network_id: 4,
        gas: 4500000,
        gasPrice: 10000000000,
    }

  },
  solc: {

    version: "0.4.24",
      settings: {
        optimizer: {
          enabled: true,
          runs: 200  // Optimize for how many times you intend to run the code
        },

      }
  }
};

迁移档案;

代码语言:javascript
复制
module.exports = async function(deployer, network, accounts) {
  const _name = "Dinar Coin";
  const _symbol = "DNC";
  const _decimals = 18 ;
  await deployer.deploy(DinarCoin, _name, _symbol, _decimals);
  const deployedToken = await DinarCoin.deployed();

  const latestTime = (new Date).getTime();

  const _rate           = 500;
  const _wallet         = '0x7b179f369451782679aCc04f9799193E67f14f74'; // TODO: Replace me
  const _token          = deployedToken.address;
  const _openingTime    = latestTime + duration.minutes(1);
  const _closingTime    = _openingTime + duration.weeks(10);
  const _cap            = ether(100);
  const _goal           = ether(50);
  const _foundersFund   = '0x7b179f369451782679aCc04f9799193E67f14f74'; // TODO: Replace me
  const _foundationFund = '0x7b179f369451782679aCc04f9799193E67f14f74'; // TODO: Replace me
  const _partnersFund   = '0x7b179f369451782679aCc04f9799193E67f14f74'; // TODO: Replace me
  const _releaseTime    = _closingTime + duration.days(1);

  await deployer.deploy(
    DinarCrowdsale,
    _rate,
    _wallet,
    _token,
    _cap,
    _openingTime,
    _closingTime,
    _goal,
    _foundersFund,
    _foundationFund,
    _partnersFund,
    _releaseTime
  );

  return true;
};
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/73066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档