0

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: if (now <= BonusAdded) { tokens = msg.value * 4500; } else { tokens = msg.value * 3000; } 

Appreciate any advice

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

1 Answer 1

0

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 // totalTokens = balances[msg.sender].safeAdd(tokensPurchasing); // else uint totalTokens = tokensPurchasing ; // check eligibility for Bonus if(totalTokens > minLimitToGetBonus){ tokensPurchasing = tokensPurchasing .safeMul(1500).safeDiv(100); // 50% bonus } balances[msg.sender] = safeAdd(balances[msg.sender], tokensPurchasing); _totalSupply = safeAdd(_totalSupply, tokensPurchasing); Transfer(address(0), msg.sender, tokensPurchasing); owner.transfer(msg.value); } } 
6
  • 1
    Thankyou i can see your idea and will play with it .I was thinking i need to add condition to this function in the solidity crowdsale contract. ´ function _updatePurchasingState(address _beneficiary, uint256 _weiAmount) internal {´ Thanx ps how do i get those back ticks around code lol Commented Apr 2, 2018 at 11:43
  • Happy to help. If you have multiple discount structure, better break the discount calculation in another function. Commented Apr 2, 2018 at 13:41
  • 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); Commented Apr 2, 2018 at 14:49
  • why there is if (true). Code will always execute this condition and never move to else. Check edit in answer. Commented Apr 3, 2018 at 1:51
  • @ Prashant <br/> what about this approach ? pros ,cons with many ifs ?. <br/> ` function getRate ()view return (unit){ if (now > (startTime(1 week))){return 1000} if (now > (startTime (2 weeks))){return 500} ` <br/> thx on true issue i learn allot Commented Apr 4, 2018 at 9:52

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.