[Ethereum] how to define start time and end time of crowdsale in constructor

crowdsaletimestamp

I am pretty much stuck with my crowdsale contract. I think i am missing the correct entries in the constructor like time and rate. Can someone help me on how to fill in the correct values? I am working with the Open-zeppelin crowdsale. Everytime i send ether to the deployed and verified contract, the transaction fails, (cancelled) and probably bc of a revert() it says. This is most likely my fault because i think i enter the wrong parameters in the constructor, but i don't seem to figure out what exactly i am doing wrong.

The zeppelin crowdsale code is this :

pragma solidity ^0.4.18;

import "./MiniMeToken.sol";
import "./SafeMath.sol";


/**
* @dev Crowdsale is a base contract for managing a token crowdsale.
* Crowdsales have a start and end timestamps, where investors can make
* token purchases and the crowdsale will assign them tokens based
* on a token per ETH rate. Funds collected are forwarded to a wallet
* as they arrive. The contract requires a MintableToken that will be
* minted as contributions arrive, note that the crowdsale contract
* must be owner of the token in order to be able to mint it.
*/
contract Crowdsale {
using SafeMath for uint256;

// The token being sold
MiniMeToken public token;

// start and end timestamps where investments are allowed (both inclusive)
uint256 public startTime;
uint256 public endTime;

// address where funds are collected
address public wallet;

// how many token units a buyer gets per wei
uint256 public rate;

// amount of raised money in wei
uint256 public weiRaised;

/**
* event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, 
uint256 value, uint256 amount);


function Crowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, 
address _wallet, MiniMeToken _token) public {
require(_startTime >= now);
require(_endTime >= _startTime);
require(_rate > 0);
require(_wallet != address(0));
require(_token != address(0));

startTime = _startTime;
endTime = _endTime;
rate = _rate;
wallet = _wallet;
token = _token;
}

 // fallback function can be used to buy tokens
 function () external payable {
 buyTokens(msg.sender);
 }

 // low level token purchase function
 function buyTokens(address beneficiary) public payable {
 require(beneficiary != address(0));
 require(validPurchase());

 uint256 weiAmount = msg.value;

// calculate token amount to be created
uint256 tokens = getTokenAmount(weiAmount);

// update state
weiRaised = weiRaised.add(weiAmount);

token.generateTokens(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);

forwardFunds();
}

// @return true if crowdsale event has ended
function hasEnded() public view returns (bool) {
return now > endTime;
}

// Override this method to have a way to add business logic to your 
crowdsale when buying
function getTokenAmount(uint256 weiAmount) internal view returns(uint256) {
return weiAmount.mul(rate);
}

// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds() internal {
wallet.transfer(msg.value);
}

// @return true if the transaction can buy tokens
function validPurchase() internal view returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = msg.value != 0;
return withinPeriod && nonZeroPurchase;
}

}

And the testcrowdsale is this :

pragma solidity ^0.4.18;

import "./CappedCrowdsale.sol";
import "./RefundableCrowdsale.sol";
import "./MiniMeToken.sol";



/**
 * @title EtceteraCrowdsale
 * @dev This is a fully fledged crowdsale.
 * The way to add new features to a base crowdsale is by multiple 
 inheritance.
 * In this example we are providing following extensions:
 * CappedCrowdsale - sets a max boundary for raised funds
 * RefundableCrowdsale - set a min goal to be reached and returns funds if 
 it's not met
 *
 * After adding multiple features it's good practice to run integration 
 tests
 * to ensure that subcontracts works together as intended.
 */
 contract EtceteraCrowdsale is CappedCrowdsale, RefundableCrowdsale {

 function EtceteraCrowdsale(uint256 _startTime, uint256 _endTime, uint256 
 _rate, uint256 _goal, uint256 _cap, address _wallet, MiniMeToken _token) 
 public
 CappedCrowdsale(_cap)
 FinalizableCrowdsale()
 RefundableCrowdsale(_goal)
 Crowdsale(_startTime, _endTime, _rate, _wallet, _token)
 {
  //As goal needs to be met for a successful crowdsale
  //the value needs to less or equal than a cap which is limit for accepted 
 funds
 require(_goal <= _cap);
 }
 }

My parameters in the constructor for deployment are the following :

"1517199000","1519877400","0.0000000008440100605999225",
"1688020121199844900000","22788271636197904000000","wallet address 
here","token address here"

According to me the ICO should start at 01/29/2018 @ 4:10am (UTC) and end at 03/01/2018 @ 4:10am (UTC) … Am i wrong here?

Best Answer

Limiting myself to the question, the answer is "in unix timestamp". I sugest visit this tutorial https://github.com/poanetwork/token-wizard/wiki/Set-Crowdsale-Start-and-End-Time, in the sixth point the writer refers you to this page https://www.unixtimestamp.com/index.php where you can try to convert date in unix timestamp. I hope it helps someone with the same question.

Related Topic