I am trying to deploy simple ERC20 token and simple Crowdsale contract into ropsten network with locally installed Truffle, but received this error: The contract code couldn't be stored, please check your gas amount
error message
truffle migrate --reset --network ropsten
Using network 'ropsten'.
Running migration: 1_initial_migration.js
Replacing Migrations...
... 0x0ff37e7ba5a0eb4f8600984db8ba13fac80f5e6c085a4254afa31dae741e2fef
Migrations: 0x268c318e2a04a6fdcba5b03a43f2ffda4f2b6e80
Saving successful migration to network...
... 0x65a0aa077ad45c1b8e4735d36622f20f805192ac1b913cb281c30c978781947f
Saving artifacts...
Running migration: 2_deploy_contracts.js
Running step...
Deploying SampleCrowdsaleToken...
... 0x5c865b9cbef7a35145ef60c6b4f6be02c4c974d33d0ccbf28698975b02b81f6a
SampleCrowdsaleToken: 0xbfb19138461daeed076e179593212d870c14204d
Deploying SampleCrowdsale...
... 0x6a6bbcaa614999d4e09e6a73263ebf7a3e217695c113d50a9d3f23a7ccca5a57
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 (/home/haibing/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/contract.js:147:1)
at /home/haibing/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/method.js:142:1
at /home/haibing/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:89:1
at /home/haibing/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/~/truffle-core/~/truffle-migrate/index.js:225:1
at /home/haibing/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1
at XMLHttpRequest.request.onreadystatechange (/home/haibing/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
at XMLHttpRequestEventTarget.dispatchEvent (/home/haibing/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
at XMLHttpRequest._setReadyState (/home/haibing/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
at XMLHttpRequest._onHttpResponseEnd (/home/haibing/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
at IncomingMessage.<anonymous> (/home/haibing/.nvm/versions/node/v9.11.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
at IncomingMessage.emit (events.js:185:15)
at endReadableNT (_stream_readable.js:1106:12)
at process._tickCallback (internal/process/next_tick.js:178:19)
token contract:
pragma solidity ^0.4.18;
import 'zeppelin-solidity/contracts/token/ERC20/MintableToken.sol';
/**
* @title SampleCrowdsaleToken
* @dev Very simple ERC20 Token that can be minted.
* It is meant to be used in a crowdsale contract.
*/
contract SampleCrowdsaleToken is MintableToken {
string public constant name = "Sample Crowdsale Token"; // solium-disable-line uppercase
string public constant symbol = "SCT"; // solium-disable-line uppercase
uint8 public constant decimals = 18; // solium-disable-line uppercase
}
crowdsale contract:
pragma solidity ^0.4.18;
import "zeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "zeppelin-solidity/contracts/crowdsale/distribution/RefundableCrowdsale.sol";
import "zeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol";
import "./SampleCrowdsaleToken.sol";
/**
* @title SampleCrowdsale
* @dev This is an example of a fully fledged crowdsale.
* The way to add new features to a base crowdsale is by multiple inheritance.
* In this example we are providing following extensions:
* CappedCrowdsale - sets a max boundary for raised funds
* RefundableCrowdsale - set a min goal to be reached and returns funds if it's not met
*
* After adding multiple features it's good practice to run integration tests
* to ensure that subcontracts works together as intended.
*/
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale {
function SampleCrowdsale(uint256 _openingTime, uint256 _closingTime, uint256 _rate, address _wallet, uint256 _cap, MintableToken _token, uint256 _goal) public
Crowdsale(_rate, _wallet, _token)
CappedCrowdsale(_cap)
TimedCrowdsale(_openingTime, _closingTime)
RefundableCrowdsale(_goal)
{
//As goal needs to be met for a successful crowdsale
//the value needs to less or equal than a cap which is limit for accepted funds
require(_goal <= _cap);
}
}
Migration JS file:
var SampleCrowdsale = artifacts.require("SampleCrowdsale");
var SampleCrowdsaleToken = artifacts.require("SampleCrowdsaleToken");
module.exports = function(deployer, network, accounts)
{
const startTime = Date.now()/1000|0 + 120;
const endTime = startTime + (3600 * 1 * 1); // *1 hour *1 days
const ethRate = new web3.BigNumber(100);
const wallet = accounts[0];
return deployer
.then(() => {
return deployer.deploy(SampleCrowdsaleToken);
})
.then(() => {
return deployer.deploy(
SampleCrowdsale,
startTime,
endTime,
ethRate,
wallet,
100000000000000000000,
SampleCrowdsaleToken.address,
200000000000000000000
);
}).then(() => {
// TODO: transfer ownerhship of the token to the crowdsale for minting
// Currently doing that in the UI
});
};
truffle.js
module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// for more about customizing your Truffle configuration!
networks: {
development: {
host: "127.0.0.1",
port: 9545,
network_id: "*" // Match any network id
},
ropsten: {
host: "localhost",
port: 8545,
network_id: "*",
gas: 4712388,//4000000, // <--- Twice as much
gasPrice: 100000000000,
from: "0x986ccba35d50e5f3b7a7c895ebce9212c343f691"
}
}
};
Environment:
Truffle v4.1.8 (core: 4.1.8)
Solidity v0.4.23 (solc-js)
Geth
Version: 1.8.7-stable
Git Commit: 66432f3821badf24d526f2d9205f36c0543219de
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10
Operating System: linux
GOPATH=
GOROOT=/usr/lib/go-1.10