I'm trying to deploy the following crowdsale contract(extended from openzeppelin) to the ropsten test network using the remix IDE.
The contracts compile but throws errors(Gas limit exceeded) when i try to deploy.
The errors seem ambiguous to me as I have increased the gas price and limit but still have the same problem

the code is given below:

pragma solidity ^0.4.23;

import "../node_modules/zeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol";
import "../node_modules/zeppelin-solidity/contracts/crowdsale/distribution/RefundableCrowdsale.sol";
import "../node_modules/zeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol";

contract SaleContract is CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale {
  // solium-disable operator-whitespace

  event refund(string why, address beneficiary);
  event sentExternalTokens(uint256 amount);

  uint8 public constant decimals = 18;

  uint256 public presaleStarts;
  uint256 public crowdsaleStartTime;
  uint256 public presaleRate;
  uint256 public crowdsaleRate;
  uint256 public presaleRaised;
  uint256 public externalTokensSent;

  uint256 public constant maxTokens       = 6000000 * 10 ** uint256(decimals);
  uint256 public constant totalSaleTokens = 5000000 * 10 ** uint256(decimals);
  uint256 public constant presaleTokens   = 2000000 * 10 ** uint256(decimals);

  uint256 public reservedTokens  = 1000000 * 10 ** uint256(decimals);

   * @dev vary rate according to block time.
  modifier rateMod {
    // solium-disable-next-line security/no-block-members
    if (block.timestamp >= crowdsaleStartTime) rate = crowdsaleRate;
    else rate = presaleRate;

   * @dev prevent purchase when limit exceeded.
  modifier limitCheck {    
    uint256 tokensTomint   = msg.value.mul(rate);
    uint256 totalAfterMint = token.totalSupply() + tokensTomint;

    // solium-disable-next-line security/no-block-members
    if ((block.timestamp < crowdsaleStartTime) && (totalAfterMint > presaleTokens)) {
      msg.sender.transfer(msg.value); // Refund them
      emit refund("presale limit hit, refunding ", msg.sender);

      uint256 _openingTime,
      uint256 _crowdsaleStartTime,
      uint256 _closingTime,
      uint256 _presaleRate,
      uint256 _crowdsaleRate,
      uint256 _goal,
      uint256 _cap,
      MintableToken _token,
      address _wallet
    Crowdsale(_presaleRate, _wallet, _token)
    TimedCrowdsale(_openingTime, _closingTime)
    require(_openingTime < _crowdsaleStartTime);
    require(_goal <= _cap);

    crowdsaleStartTime = _crowdsaleStartTime;

    presaleRate     = _presaleRate;
    crowdsaleRate   = _crowdsaleRate;        

   * @dev Extend parent behavior requiring purchase to consider emission rate based on ~time.
   * @param _beneficiary Token purchaser
   * @param _weiAmount Amount of wei contributed
  function _preValidatePurchase(
    address _beneficiary,
    uint256 _weiAmount
    rateMod           // **set appropriate rate**  
    limitCheck        // **verify limits**   
    super._preValidatePurchase(_beneficiary, _weiAmount);

   * @dev update state variables
   * @param _beneficiary Address performing the token purchase
   * @param _weiAmount Value in wei involved in the purchase
  function _updatePurchasingState(
    address _beneficiary,
    uint256 _weiAmount
    // solium-disable-next-line security/no-block-members
    if (block.timestamp < crowdsaleStartTime) {
      presaleRaised = presaleRaised.add(msg.value);

    super._updatePurchasingState(_beneficiary, _weiAmount);

  function sendExternalTokens(address[] recipients, uint amount) onlyOwner public {
    require(amount > 0);

    uint256 totalToTransfer = recipients.length.mul(amount);

    require((token.totalSupply() + totalToTransfer) < maxTokens);

    for (uint256 i = 0; i < recipients.length; i++) {
      _deliverTokens(recipients[i], amount);

    externalTokensSent = externalTokensSent.add(totalToTransfer);
    emit sentExternalTokens(totalToTransfer);  

  function finalize(address _reserveWallet) onlyOwner public {

    uint256 existingTokens = token.totalSupply();
    require(existingTokens < maxTokens);

    uint256 unsoldTokens = totalSaleTokens - existingTokens;

    if (unsoldTokens > 0) {
      reservedTokens = reservedTokens + unsoldTokens;

    _deliverTokens(_reserveWallet, reservedTokens);

  • what errors are thrown? – Badr Bellaj Jul 18 '18 at 7:28
  • @BadrBellaj, Gas limit exceeded, the errors seem ambiguous to me as I have increased the gas price and limit but still have the same problem – Skope martin Jul 18 '18 at 8:08
  • Which parameters are you using when deploying ? – Tclairet Jul 18 '18 at 8:38

I managed to deploy on Rinkeby Network. Therefore, I will introduce my way.

  1. Compile the code and deploy MintableToken to Rinkeby Using Remix
  2. Get Mintable Token Address, deploy SaleContract with known Mintable Token address to Rinkeby
  3. There may exist some problems with your parameters. My parameters to initialize as following 1541902893,1551902893,1571902893,3,4,5,6,"0xd40e809eefe17efca14aa4604de7f8599cdf8871","0xca35b7d915458ef540ade6068dfe2f44e8fa733c"

Rinkeby(Mintable) : https://rinkeby.etherscan.io/address/0xd40e809eefe17efca14aa4604de7f8599cdf8871 Rinkeby(SaleContract) : https://rinkeby.etherscan.io/address/0xf959a499a514f80f07d4e6f26517aefca4da8c23

PS: I imported open-zeppelin libraries from github and it is suggested during development phase import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol"; import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/crowdsale/distribution/RefundableCrowdsale.sol"; import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol";


I'm unsure if Remix behaves the same way, but for me when trying to deploy contract with Truffle these gas errors are usually caused by errors in the code. The errors pass the compiler but are triggered when trying to deploy.

Some such errors are problems with contract inheritance (missing a constructor call from sub-contract for example).

I suggest you remove pieces of the code until you find out what causes the issue. Your code is nothing too complicated so it shouldn't be a real gas issue (if you just put a decent gas limit).

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.