These are chat archives for ethereum/tutorials

29th
Apr 2016
Daniel Spiteri
@DanielSpiteri75
Apr 29 2016 04:12
hello Everyone ! ;)
Makoto Inoue
@makoto
Apr 29 2016 08:42

Good morning. I have a noob question. Is there any way for Solidity to restrict amount of value to be sent? For example in the token example,

function buy() returns (uint amount){
    amount = msg.value / buyPrice;                     // calculates the amount
    if (balanceOf[this] < amount) throw;               // checks if it has enough to sell
    balanceOf[msg.sender] += amount;                   // adds the amount to buyer's balance
    balanceOf[this] -= amount;                         // subtracts amount from seller's balance
    Transfer(this, msg.sender, amount);                // execute an event reflecting the change
    return amount;                                     // ends function and returns
}

buy() function is only checking the balance of the contract itself, but not limiting the amount of msg.value. Though I can control how much to send at Javascript level, are there any way to gurantee the amount you can send per transaction at contract level?

Alex Van de Sande
@alexvandesande
Apr 29 2016 09:35
@makoto sure
`if (msg.value > maxValue) throw'
Makoto Inoue
@makoto
Apr 29 2016 12:32
@alexvandesande thanks