首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能在Rinkeby或Ropsten上部署智能合同

不能在Rinkeby或Ropsten上部署智能合同
EN

Stack Overflow用户
提问于 2017-11-16 13:16:25
回答 4查看 2.9K关注 0票数 2

我一直在尝试设置基于演示ethereum的ICO融合本教程,但是每次我尝试将合同部署到Ropsten或Rinkeby时,都会出现以下错误:

代码语言:javascript
复制
Running migration: 2_deploy_contracts.js
  Deploying SuperHeroTokenThreeCrowdsale...
  ... 0x9d0da17f00192993720639abceecc2b33c5fbb9a29dd43fa6e1abd0ce6aecc5d
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.
    at Object.callback (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:314870:46)
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:35060:25
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:316808:9
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:164746:11
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:294942:9
    at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:296367:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:164934:18)
    at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:165224:12)
    at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:165379:12)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:165339:24)
  • 系统: Ubuntu 16.04
  • 松露: v4.0.0-beta.2
  • Geth: 1.7.2-稳定
  • OpenZeppelyn坚固度1.3.0

truffle.js:

代码语言:javascript
复制
module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      gas: 4700000, 
      from: '0x24182550B8630629501AC11f5568dbb7EE18dBd2',
      network_id: "*" // Match any network id
    },
  }
};

另外,我不得不说,我的Rinkeby帐户上有乙醚。另一个注意事项--如果我将它部署到TestRpc,它工作得很好,我可以购买我的定制令牌,而且一切都很好。我试过调整煤气量,但没什么变化。

有什么好主意吗?

EN

回答 4

Stack Overflow用户

发布于 2017-11-27 14:22:30

这份合同可能太大了,不能达到汽油限额。尝试将gasLimit设置为很高的值,比如genesis.json中的0x60000000000000。这样,您可以增加您的气体: 6000000在truffle.js。这应该足以部署您的合同。

票数 1
EN

Stack Overflow用户

发布于 2017-12-19 07:21:35

我也面临着同样的问题,下面是我为解决这个错误所做的工作。

首先要记住的是部署使用齐柏林飞艇的智能合同,在您所遵循的教程中,它使用了大量的气体值。我能够在testrpc上部署合同,但无法在testnet (rinkeby和ropsten)上部署。当我监视testrpc控制台时,合同中使用了5200000的气体。当压块极限为(https://ropsten.infura.io)为4700000时。因此,我的合同没有被部署到那里,而且也造成了同样的错误。如果增加truffle.js文件中的气体量,就会出现“超过块气体限制”的错误。

因此,我选择在Rinkeby网络上部署契约,并在truffle.js文件中进行以下配置。请确保使用npm安装安装npm依赖项。

代码语言:javascript
复制
require('dotenv').config();
const Web3 = require("web3");
const web3 = new Web3();
const WalletProvider = require("truffle-wallet-provider");
const Wallet = require('ethereumjs-wallet');

var rinkebyPrivateKey = new Buffer(process.env["RINKEBY_PRIVATE_KEY"], "hex")
var rinkebyWallet = Wallet.fromPrivateKey(rinkebyPrivateKey);
var rinkebyProvider = new WalletProvider(rinkebyWallet, "https://rinkeby.infura.io/");

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      gas: 6700000,
      from: "0x2abdf05db2c9632ab240ee59963816f09e6d3e5a",
      network_id: "*" // Match any network id
    },
    rinkeby: {
      provider: rinkebyProvider,
      gas: 6700000,
      gasPrice: web3.toWei("20", "gwei"),
      network_id: "2",
    }
  },
  solc: {
    optimizer: {
      enabled: true,
      runs: 200
    }
  }
};

我希望它能帮助你解决问题。万一有什么事,请告诉我。

票数 1
EN

Stack Overflow用户

发布于 2017-12-21 10:03:19

看起来代码中有一些错误。这个信息完全是误导的。不需要更改truffle.js中的gas值

在更改2_deploy_contracts.js中的startTimeendTime后,可以将合同部署到rinkeby。

代码语言:javascript
复制
const IcoMyCoin = artifacts.require("./MyCoinCrowdsale.sol");
const duration = {
    seconds: function(val) { return val},
    minutes: function(val) { return val * this.seconds(60) },
    hours:   function(val) { return val * this.minutes(60) },
    days:    function(val) { return val * this.hours(24) },
    weeks:   function(val) { return val * this.days(7) },
    years:   function(val) { return val * this.days(365)}
};

module.exports = function(deployer, network, accounts) {
    const startTime = web3.eth.getBlock('latest').timestamp + duration.minutes(1);
    const endTime = startTime + duration.minutes(30);
    const rate = new web3.BigNumber(1000);
    const wallet = '<< YOUR WALLET ADDRESS>>';

    deployer.deploy(IcoMyCoin, startTime, endTime, rate, wallet)
};
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47330668

复制
相关文章

相似问题

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