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

  • What exactly is your problem? – Prashant Prabhakar Singh Apr 2 '18 at 11:23
  • how to set a minimum investment needed to receive above bonus. – Trac3y Apr 2 '18 at 11:25
  • Minimum investment means? Min amount of tokens? ethers? – Prashant Prabhakar Singh Apr 2 '18 at 11:26
  • Minimum Tokens bought with Ether to receive the bonus – Trac3y Apr 2 '18 at 11:27
  • EX. You need to buy a minimum of 30000 Tokens @ 3000\Eth to get a 50% bonus. – Trac3y Apr 2 '18 at 11:34
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);
    }
}
  • 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 – Trac3y Apr 2 '18 at 11:43
  • Happy to help. If you have multiple discount structure, better break the discount calculation in another function. – Prashant Prabhakar Singh Apr 2 '18 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); – Trac3y 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. – Prashant Prabhakar Singh Apr 3 '18 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 – Trac3y Apr 4 '18 at 9:52

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.