# Set minimum purchase condition ideas needed :)

I am quite the beginner and trying to get my head around things using Remix practice building contracts.

I want to set a minimum total purchase required(amount Tokens) I am using " https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/crowdsale/Crowdsale.sol" as my starting point.

now i want to require set minimum to get a bonus like

``````// from BokkyPooBah MyToken example:

tokens = msg.value * 4500;
} else {
tokens = msg.value * 3000;
}
``````

• What exactly is your problem? Apr 2 '18 at 11:23
• how to set a minimum investment needed to receive above bonus. Apr 2 '18 at 11:25
• Minimum investment means? Min amount of tokens? ethers? Apr 2 '18 at 11:26
• Minimum Tokens bought with Ether to receive the bonus Apr 2 '18 at 11:27
• EX. You need to buy a minimum of 30000 Tokens @ 3000\Eth to get a 50% bonus. Apr 2 '18 at 11:34

Check if this helps

``````uint public minLimitToGetBonus = 1000 * (10 ** decimals)
function getToken() public {
if(balances[msg.sender] > minLimitToGetBonus){
// give bonus
}
else{
// process normally
}
}
``````

Edit 1: As per discussion in comments:

``````contract BunusCoin{
uint minLimitToGetBonus = 1000;
bool InTime = true;
uint rate = 3000;

mapping(address => uint ) public balances;

function NoMoreHoops() public payable{
require(InTime);
uint tokensPurchasing = msg.value * rate ; // no of tokens purchasing
//  if you want to consider prev balances as well. Uncomment below line
// else
// check eligibility for Bonus
if(totalTokens > minLimitToGetBonus){
• Is it a mess ?`function NoMoreHoops () public payable { require minLimitToGetBonus <= 1000; require InTime = true; uint tokens; if ( true) { tokens = msg.value * 4500; \\ +50% during first week if buying min 1000 } else { tokens = msg.value * 3000; \\ No Bonus sry } } balances[msg.sender] = safeAdd(balances[msg.sender], tokens); _totalSupply = safeAdd(_totalSupply, tokens); Transfer(address(0), msg.sender, tokens); owner.transfer(msg.value);` Apr 2 '18 at 14:49
• why there is `if (true)`. Code will always execute this condition and never move to else. Check edit in answer. Apr 3 '18 at 1:51