I am deploying a crowdsale contract in Remix but no matter how high I set the gas limit (set it to 40000000 once) or even how much I change the value field I can't get this contract to not exceed the gas limit. The other contract I deployed was much larger and it deployed fine so I am thinking there is something wrong with my code. Here it is

pragma solidity ^0.4.19;

 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
library SafeMath {
  function mul(uint256 a, uint256 b) internal constant returns (uint256) {
    uint256 c = a * b;
    assert(a == 0 || c / a == b);
    return c;

  function add(uint256 a, uint256 b) internal constant returns (uint256) {
    uint256 c = a + b;
    assert(c >= a);
    return c;

 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
contract Ownable {

  address public owner;

   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
   * account.
  function Ownable() {
    owner = msg.sender;

   * @dev Throws if called by any account other than the owner.
  modifier onlyOwner() {
    require(msg.sender == owner);

   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
  function transferOwnership(address newOwner) onlyOwner {
    require(newOwner != address(0));
    owner = newOwner;

 * @title Token
 * @dev API interface for interacting with the BQPOT Token contract 
interface Token {
  function transfer(address _to, uint256 _value) returns (bool);
  function balanceOf(address _owner) constant returns (uint256 balance);

contract Crowdsale is Ownable {

    using SafeMath for uint256;

    Token token;

    uint256 public constant RATE = 1000; //Tokens per Ether
    uint256 public constant CAP = 73; //Cap in Ether
    uint256 public constant START = 1517383764; //Must change for timestamp
    uint256 public DAYS = 1; //Preorder lasts for 14 DAYS

    bool public initialized = false;
    uint256 public raisedAmount = 0;

    // Who bought tokens and how many?
    event BoughtTokens(address indexed to, uint256 value);

    //Is the sale active?
    modifier whenSaleIsActive() {
    //Pass in token contract address
    function Crowdsale(address _tokenAddr){
        require(_tokenAddr !=0);
        token = Token(_tokenAddr);
    //Makes sure there is correct amount of tokens sent to address
    function initialize(uint256 numTokens) onlyOwner {
        require(initialized == false);
        require(tokensAvailable() ==numTokens); //Make sure tokens are available
        initialized = true; //If they check out set initialize to true

    function isActive() constant returns (bool) {
        return (
            initialized == true && //Is contract initialized?
            now >= START && //To be active it must be after the start date
            now <= START.add(DAYS * 1 days) && //Before end date
            goalReached() == false //Also Goal is not yet reached 
    function goalReached() constant returns (bool) {
        return (raisedAmount >= CAP * 1 ether);

    function () payable {

    function buyTokens() payable whenSaleIsActive{

        uint256 weiAmount = msg.value;
        uint256 tokens = weiAmount.mul(RATE);

        BoughtTokens(msg.sender, tokens);
        //Add to amount raised 
        raisedAmount = raisedAmount.add(msg.value);

        //Send buyer tokens
        token.transfer(msg.sender, tokens);

        //Send ether to owner

    //Return number of tokens allocated to contract
    function tokensAvailable() constant returns (uint256) {
        return token.balanceOf(this);

    //Stop contract and refund the owner
    function destroy() onlyOwner {
        //Send rest of tokens to the owner
        uint256 balance = token.balanceOf(this);
        assert(balance > 0);
        token.transfer(owner, balance);

        //Incase ether is left in contract

  • Have you missed some code? Where is Ownable coming from? – Nanolucas Jan 31 '18 at 7:46
  • Sorry I am a complete newbie at posting code on this exchange I seem to screw up the formatting. There are a number of open zepplin codes above the contract. How can I properly format them to all fit? – darknightsy Jan 31 '18 at 7:53
  • Look at the formatting links in the stackexchange post editor, it will show you how to wrap code (in backticks) so that it displays correctly. – Nanolucas Jan 31 '18 at 7:58
  • Sorry about that. Thank you in advance for your patience! – darknightsy Jan 31 '18 at 8:00
  • Unfortunately I can't see any obvious reasons why it'd be exceeding the gas limit when you try to deploy. The only suggestions I can really make are that you should be defining the visibility of each of your functions (public, private, external, internal) and to use 'view' or 'pure' instead of the deprecated 'constant' in function declarations. – Nanolucas Jan 31 '18 at 8:19

I'm not sure but could be this :

When deploying you instance the following instruction :

token = Token(_tokenAddr);

However Token is defined as the following :

interface Token {
    function transfer(address _to, uint256 _value) returns (bool);
    function balanceOf(address _owner) constant returns (uint256 balance);

I'd see two points here :

  1. This is an interface, not a contract and so shouldn't be used as instanciable directly ( it should be used to base another contract ).

  2. Even if it wasn't an Interface there is not constructor in it, and event with constructor, you should have to specify an argument in the signature call of the constructor as you pass an argument on deployment.

| improve this answer | |
  • I have a token contract that I have deployed without issue and was using interface to connect with it but I can't seem to deploy this crowdsale still. Do you think it may be better to make a basic token function and put it into the crowdsale contract directly? Therefore making the interface unnecessary. If so where would you recommend I place it? – darknightsy Feb 1 '18 at 0:47
  • There was no problem to deploy Crowdsale in Javascript vm environment. Where are you trying to deploy it ? – Rob Magier Jul 3 '18 at 4:39

I deployed your CrowdSale contract in Remix IDE using the Javascript VM with no issues.

creation of Crowdsale pending...
[vm]from:0xca3...a733cto:Crowdsale.(constructor)value:0 wei data:0x608...77b3alogs:0hash:0x650...40b38 

status  0x1 Transaction mined and execution succeed
transaction hash    0x65017f107f3c5309590ff765861ad0dd0f6bb2b6bee5c60bf99c5bdbe0340b38
contract address    0xbbf289d846208c16edc8474705c748aff07732db
from    0xca35b7d915458ef540ade6068dfe2f44e8fa733c
to  Crowdsale.(constructor)
gas     3000000 gas 
transaction cost    941985 gas 
execution cost  677381 gas 
hash    0x65017f107f3c5309590ff765861ad0dd0f6bb2b6bee5c60bf99c5bdbe0340b38
input   0x608...77b3a
decoded input   {
    "address _tokenAddr": "0x692a70D2e424a56D2C6C27aA97D1a86395877b3A"
decoded output   - 
logs    []
value   0 wei 

I think without further details of how you're deploying, e.g. environment, other contract deployment, there's no way to troubleshoot this further.

| improve this answer | |

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.