Solidity

設置所需的最低購買條件想法:)

  • April 3, 2018

我是一個初學者,並試圖通過 Remix 練習建構契約來解決問題。

我想設置所需的最低總購買量(令牌數量)我使用“ https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/crowdsale/Crowdsale.sol ”作為我的起點。

現在我想要求設置最低限度才能獲得類似的獎金

// from BokkyPooBah MyToken example:

if (now <= BonusAdded) {   
           tokens = msg.value * 4500;
       } else {
           tokens = msg.value * 3000;
       }

感謝任何建議

檢查這是否有幫助

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

編輯1: 根據評論中的討論:

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);
   }
}

引用自:https://ethereum.stackexchange.com/questions/44518