Creating constructor for Crowdsale contract

Creating constructor for Crowdsale
:computer: Environment

Remix, Solidity 0.5.0
:memo:Details

I am trying to create constructor for the below crowdsale contract. Questions inside the code//
:1234: Code to reproduce

pragma solidity ^0.5.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/docs-v2.x/contracts/crowdsale/Crowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/docs-v2.x/contracts/crowdsale/emission/AllowanceCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/docs-v2.x/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/docs-v2.x/contracts/crowdsale/validation/TimedCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/docs-v2.x/contracts/crowdsale/distribution/RefundablePostDeliveryCrowdsale.sol";


contract MyTokenCrowdsale is
    Crowdsale,
    AllowanceCrowdsale,
    CappedCrowdsale,
    TimedCrowdsale,
    RefundablePostDeliveryCrowdsale
{
    constructor(
        uint256 rate,
        address payable wallet,
        IERC20 token,
        address tokenWallet,
        uint256 cap,
        uint256 openingTime,
        uint256 closingTime,
        uint256 goal
    )
        public
        AllowanceCrowdsale(tokenWallet)
        CappedCrowdsale(cap)
        TimedCrowdsale(openingTime, closingTime)
        Crowdsale(rate, wallet, token) // If I want a rate of 0.00088 ETH per Token, How?
        RefundablePostDeliveryCrowdsale() // is this correct, what should I refer it to?Its empty()
        RefundableCrowdsale(goal)
    {
        // If this is included do I need to include as well
        ////////////////////////////////////////////////// RefundablePostDeliveryCrowdsale in the constructor??
    }
}
1 Like

Hi @ETHERC20,

:warning: Note: You should only use code published in an official release of OpenZeppelin Contracts, the latest 2.x release is 2.5.1.

Your code was importing from docs-v2.x branch which is not an official release, you should change this to v2.5.1

To calculate the rate that you want, please see the documentation: https://docs.openzeppelin.com/contracts/2.x/crowdsales#crowdsale-rate

I recommend that your contracts are appropriately tested and audited.

With updated imports, your contract could look like the following.
:warning: Please note I haven’t tested this.

pragma solidity ^0.5.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/crowdsale/Crowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/crowdsale/emission/AllowanceCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/crowdsale/validation/TimedCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/crowdsale/distribution/RefundablePostDeliveryCrowdsale.sol";


contract MyTokenCrowdsale is
    Crowdsale,
    AllowanceCrowdsale,
    CappedCrowdsale,
    TimedCrowdsale,
    RefundablePostDeliveryCrowdsale
{
    constructor(
        uint256 rate,
        address payable wallet,
        IERC20 token,
        address tokenWallet,
        uint256 cap,
        uint256 openingTime,
        uint256 closingTime,
        uint256 goal
    )
        public
        AllowanceCrowdsale(tokenWallet)
        CappedCrowdsale(cap)
        TimedCrowdsale(openingTime, closingTime)
        Crowdsale(rate, wallet, token) // calculate rate: https://docs.openzeppelin.com/contracts/2.x/crowdsales#crowdsale-rate
        RefundableCrowdsale(goal)
        RefundablePostDeliveryCrowdsale() 
        {
    }
}
1 Like