7

Problem

I get the following error after running $ truffle migrate --reset:

Running migration: 1_initial_migration.js Replacing Migrations...
... 0x5b23d046a48e2b1707155f10d3b6e12848b55167198ebcc27288a51463f2a6d6 Migrations: 0x4214c32de196e89f3aec37aa7ec58bf10e84347a Replacing TestCrowdsale... ... 0x1241cadb6818bdb0cd9698b25b6abfae472c34dfa119107691108e24198db326 Error encountered, bailing. Network state unknown. Review successful transactions manually. Error: VM Exception while processing transaction: revert at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43303:16) at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:331156:36 at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:175492:11 at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:314196:9 at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:315621:13) at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:70159:18) at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:70449:12) at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:70604:12) at IncomingMessage. (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:70564:24) at emitNone (events.js:111:20)

Environment

  • Truffle v4.0.1 (core: 4.0.1)

  • Solidity v0.4.18 (solc-js)

  • EthereumJS TestRPC v6.0.3 (ganache-core: 2.0.2)

Migrations file

My 1_initial_migration.js file looks like:

var Migrations = artifacts.require("./Migrations.sol");
var TestCrowdsale = artifacts.require("./TestCrowdsale.sol");

module.exports = function(deployer) {
   deployer.deploy(Migrations);
   deployTestCrowdsale(deployer);
};

function deployTestCrowdsale(deployer) {

   const accounts = web3.eth.accounts;

   const startTime = latestTime();
   const endTime = startTime + duration.days(45);
   const rate = 2500;
   const goal = web3.toWei(250, 'ether');
   const cap = web3.toWei(4000, 'ether');
   const wallet = accounts[0];

   return deployer.deploy(TestCrowdsale, startTime, endTime, rate, wallet);

}

function latestTime() {
  return web3.eth.getBlock('latest').timestamp;
}

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

Crowdsale file

TestCrowdsale contract uses the Zeppelin Solidity framework. My TestCrowdsale.sol file looks like:

pragma solidity ^0.4.18;

import 'zeppelin-solidity/contracts/crowdsale/Crowdsale.sol';

contract TestCrowdsale is Crowdsale {

   function TestCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet)
      Crowdsale(_startTime, _endTime, _rate, _wallet)
      public
      {
   }

}

truffle.js file looks like:

module.exports = {
   networks: {
     development: {
       host: "localhost",
       port: 8545,
       network_id: "*" // Match any network id
     }
  }
};
  • When I remove the inherited Crowdsale contract from Zeppelin Solidity, the error is gone. – Robbert Jan 18 '18 at 9:46
6

The origin of the issue is because you're trying to deploy the contract from the file migrations/1_initial_migration.js that is supposed to be used only for the deployment of Migration.sol.

To deploy your contracts, you need to create a file in migrations/2_deploy_contracts.js that contains the deployment part of TestCrowsale.sol

migrations/1_initial_migration.js

var Migrations = artifacts.require("./Migrations.sol");
module.exports = function(deployer) {
   deployer.deploy(Migrations);
};

migrations/2_deploy_contracts.js

var TestCrowdsale = artifacts.require("./TestCrowdsale.sol");

module.exports = function(deployer) {
   deployTestCrowdsale(deployer);
};

function deployTestCrowdsale(deployer) {

   const accounts = web3.eth.accounts;

   const startTime = latestTime();
   const endTime = startTime + duration.days(45);
   const rate = 2500;
   const goal = web3.toWei(250, 'ether');
   const cap = web3.toWei(4000, 'ether');
   const wallet = accounts[0];

   return deployer.deploy(TestCrowdsale, startTime, endTime, rate, wallet);

}

function latestTime() {
  return web3.eth.getBlock('latest').timestamp;
}

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

I tried on my side and the deployment go through :

Compiling ./contracts/Migrations.sol...
Writing artifacts to ./build/contracts

Using network 'development'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0x46dd08a7e00419adc52c3b9b048f89812dd960463b02125a93eb7e43eb4ca64f
  Migrations: 0x4a5a1448d37aeaaae79deed7e0d3f81ebc52db87
Saving successful migration to network...
  ... 0x573964afa1f79deca003871bd793026f7c932d9c46b8be055184e10790a63147
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Deploying TestCrowdsale...
  ... 0xd251d1b3b92facb64e38ce3e04907197e9b7b9e7fefdf083da1b43c08f1b9bb1
  TestCrowdsale: 0xd817d9295491556f00a45c8092e42c10df271865
Saving successful migration to network...
  ... 0x83a2ba140f54003fc0f146ff2d8b8e2f6d9013122d59d94a39a74d4a9c8df92e
Saving artifacts..

I pushed the code here for more details: https://github.com/gjeanmart/stackexchange/tree/master/36690-error-encountered-bailing-network-state-unknown-review-successful-transaction

  • Thanks! This works. I placed the code in the 1_initial_migrations.js file to solve another problem, but because of that I ran into this problem. – Robbert Jan 18 '18 at 10:17
4

Check any abstract/interface methods are being implemented correctly. I get this issue, where it compiles but won't deploy, when I fail to implement abstract/interface methods correctly in inheriting contracts.

Edit: Also check all the require statements in the Crowdsale constructor will pass. Maybe try with hardcoding a startTime definitely in the future in the deployment script eg 1999999999.

1

This can happen when you're using wrong initialization parameters in your Truffle migration file. As an example, let's consider the following simplified contract:

pragma solidity ^0.4.19;

contract Lease {

  function Lease(
                address _owner,
                address _tenant,
                uint _startDate,
                uint _fee,
                uint _deposit)
    public {
    require(_owner != _tenant);
    require(_startDate > now);
    require(_fee > 0);
    require(_deposit >= fee * 2);
  }
}

In order to deploy it, assume you're using the following migration file:

var Lease = artifacts.require("./Lease.sol");

module.exports = function(deployer) {
  var owner = '0xf17f52151ebef6c7334fad080c5704d77216b732';
  var tenant = '0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef';
  var startDate = 1522904400;
  var fee = 1000000000000000000;
  var deposit = 2000000000000000000;
  deployer.deploy(Lease, owner, tenant, startDate, fee, deposit);
};

When you run truffle migrate --reset you get the aforementioned error. Can you tell what's wrong?

In this case, startDate is assigned to a unix time in the past, which causes the second require statement in the contract constructor to fail.

Unfortunately, Truffle isn't specific enough about this kind of errors yet, so you have to be very careful about them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.