Matiss
Matiss

Reputation: 5349

Can't deploy smart contract on Rinkeby or Ropsten via Truffle

I've been trying to set up demo ethereum based ICO fallowing this tutorial, but each time i try to deploy contract to Ropsten or Rinkeby ir fails with this error:

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)

truffle.js:

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

Also I have to say that i have ether's on my Rinkeby account. Another note - if i deploy to TestRpc it works just fine, i can buy my custom tokens and it all works just fine. I've tried to tweak gas amount but nothing changes.

Any ideas where could be the problem?

Upvotes: 2

Views: 2977

Answers (4)

t_io
t_io

Reputation: 2022

It looks like there are some errors in the code. The message is totally misleading. There is NO need to change the gas value in truffle.js

After changing the startTime and endTime in 2_deploy_contracts.js the contract can be deployed to rinkeby.

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)
};

Upvotes: 1

Parth Trivedi
Parth Trivedi

Reputation: 51

I was also facing the same problem and here is what I did to resolve this error.

First thing to keep in mind that deploying smart contracts that uses zeppelin-solidity and in the tutorial that you followed, it uses a high amount of gas value. I was able to deploy the contract on testrpc but wasn't able to deploy on testnet (rinkeby and ropsten). When I monitored the testrpc console, the contract was using 5200000 amount of gas. Where as the block limit on ropsten is (https://ropsten.infura.io) is 4700000. Therefore my contract was not getting deployed there and it was giving the same error. If I increase the gas amount in truffle.js file, it would give me error as "Exceeds block gas limit".

Therefore I chose to deploy the contract on Rinkeby network with following configuration in truffle.js file. Please make sure to install npm dependencies using npm install ...

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
    }
  }
};

I hope it helps you resolve your issue. Please let me know in case of anything.

Upvotes: 1

ROHIT SHUKLA
ROHIT SHUKLA

Reputation: 11

I am also facing the same issue set gas: 4700036 in truffle.js file for ropsten network. It might work.

Upvotes: 0

memius
memius

Reputation: 4125

The contract might be too big for the gas limit. Try to set your gasLimit to something really high, like 0x60000000000000, in your genesis.json. This way, you can increase your gas: to 6000000 in truffle.js. This should be enough to deploy your contract.

Upvotes: 1

Related Questions