1

How do I add number of hard cap tokens in the below code (where in code), for instance 2000 ETH. I cant add it in Create of RUn (Remix) since Crowdsale and CappedCrowdsale are separate contracts.

contract CappedCrowdsale is Crowdsale {
  using SafeMath for uint256;

  uint256 public cap;

  function CappedCrowdsale(uint256 _cap) public {
    require(_cap > 0);
    cap = _cap;
  }


  function validPurchase() internal view returns (bool) {
    bool withinCap = weiRaised.add(msg.value) <= cap;
    return super.validPurchase() && withinCap;
  }


  function hasEnded() public view returns (bool) {
    bool capReached = weiRaised >= cap;
    return super.hasEnded() || capReached;
  }

}
  • 1
    I'm not sure I understand the question. The constructor takes a _cap parameter... are you just asking how to pass in a value to the constructor? – user19510 Dec 18 '17 at 15:32
  • You just need to make sure you've referenced the Crowdsale contract correctly in your CappedCrowdSale. Then you create a CappedCrowdSale contract with the capped value and the compiler will take care of creating the inherited methods and everything else that comes with the Crowdsale contract. – I.B Dec 18 '17 at 16:08
  • I mean, where in this code to add Hard cap value? – Buzzmuzz5 Dec 18 '17 at 16:58
  • Cappedcrowdsale does referwnce Crowdsale. If not correctly then can you show how? – Buzzmuzz5 Dec 18 '17 at 20:43
1

When deploying your smart-contract you have to provide _cap parameter which will be your hard cap.

in a smart-contract, the function having the same that the contract is the constructor, which is the function that is automatically called on instance creation of a class ( here class = smart-contract ).

To be able to deploy your contract you'll have to provide Crowdsale contract code source.

You can either copy-paste Crowdsale code in the same file, like this :

contract Crowdsale {
    ...
}

contract CappedCrowdsale is Crowdsale{
    ...
}

Or you can import the Crowdsale from another .sol file. If the file is in the same folder you could do :

import './Crowdsale.sol'

contract CappedCrowdsale is Crowdsale{
    ...
}

Also, note that in the partial code you gave you have the following line : using SafeMath for uint256;

Which means you'll probably have to include the SafeMath smart-contract to be able to deploy your contract.

1

Based on my understanding to your question, you might need to deploy Crowdsale Contract first and then deploy CappedCrowdsale Contract with the parameter _cap to be the hard cap I'd like to set.

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.