0

I am getting the following error when deploying with web3js a smart contract based on Open Zeppelin:

Uncaught (in promise) Error: VM Exception while processing transaction: invalid opcode
    at Object.InvalidResponse (errors.js:35)
    at requestmanager.js:86
    at XMLHttpRequest.request.onreadystatechange (httpprovider.js:122)

where the contract code is

pragma solidity ^0.4.15;

import "./libs/zeppelin/crowdsale/CappedCrowdsale.sol";
import "./libs/zeppelin/crowdsale/FinalizableCrowdsale.sol";
import './TestToken.sol';

contract SampleCrowdsale is CappedCrowdsale, FinalizableCrowdsale {

    TestToken public testToken ;

  function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet, address _tokenContractAddress)
    CappedCrowdsale(_cap)
    FinalizableCrowdsale()
    Crowdsale(_startTime, _endTime, _rate, _wallet)
  {

    testToken = TestToken(_tokenContractAddress);
  }

  function createTokenContract() internal returns (MintableToken) {
    return testToken;
  }

}

However everything works when I change FinalizableCrowdsale to RefundableCrowdsale:

pragma solidity ^0.4.15;

import "./libs/zeppelin/crowdsale/CappedCrowdsale.sol";
import "./libs/zeppelin/crowdsale/RefundableCrowdsale.sol";
import './TestToken.sol';

contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale {

    TestToken public testToken ;

  function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet, address _tokenContractAddress)
    CappedCrowdsale(_cap)
    FinalizableCrowdsale()
    Crowdsale(_startTime, _endTime, _rate, _wallet)
  {
    require(_goal <= _cap);
    testToken = TestToken(_tokenContractAddress);
  }

  function createTokenContract() internal returns (MintableToken) {
    return testToken;
  }

}

Question: Can anyone please explain to me why the first contract that uses FinalizableCrowdsale is throwing that error? RefundableCrowdsale inherits FinalizableCrowdsale but isnt giving any errors...

Related Files:

  1. https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/crowdsale/Crowdsale.sol
  2. https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/crowdsale/FinalizableCrowdsale.sol
  3. https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/crowdsale/RefundableCrowdsale.sol
1

I was able to deploy your FinalizableCrowdsale SampleCrowdsale after I removed the FinalizableCrowdsale() call from the constructor.

I used the following parameters in the constructor call:

1511030956, 1511117356, 1, 100, 200, "0x01", "0x02"

I deployed my contract using Remix, so I modified the code slightly to this (especially since I didn't have the TestToken code):


pragma solidity ^0.4.15;

import "github.com/OpenZeppelin/zeppelin-solidity/contracts/crowdsale/CappedCrowdsale.sol";
import "github.com/OpenZeppelin/zeppelin-solidity/contracts/crowdsale/FinalizableCrowdsale.sol";
import "github.com/OpenZeppelin/zeppelin-solidity/contracts/crowdsale/RefundableCrowdsale.sol";
import "github.com/OpenZeppelin/zeppelin-solidity/contracts/token/MintableToken.sol";

contract SampleCrowdsale is CappedCrowdsale, FinalizableCrowdsale {

    MintableToken public testToken ;

  function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet, address _tokenContractAddress)
    CappedCrowdsale(_cap)
    Crowdsale(_startTime, _endTime, _rate, _wallet)
  {

    testToken = MintableToken(_tokenContractAddress);
  }

  function createTokenContract() internal returns (MintableToken) {
    return testToken;
  }

}

One thing that I noticed is that RefundableCrowdsale requires one argument for its constructor, where as FinalizableCrowdsale does not and it isn't necessary to call a parent's constructor if it doesn't take any arguments.

I suspect that this minor detail is the cause of the problem.

  • When I changed _startTime from 1510889758 to 1520889758, it started working! Why is the start time important? – Nyxynyx Nov 17 '17 at 20:36

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.