0

If amount is not exactly 5 Ether it has to be refunded back to the sender.

1
  • this question is too general, because is a javascript code and you can do this with a simple condition like the others types of programming languages... check solidity documentation for learn something abaout "how you can program with solidity" – Gawey Jul 12 '17 at 14:09
3

You can add this condition in your Solidity function like this -

function foo() returns(return type) {
    if (msg.value != 5 ether) {
        throw;
    }
    // function definition
    }

The function would throw if sent value is not exactly equal to 5 ether.

or you can create a modifier and use it in your function so that condition can be checked before function execution -

modifier CheckValue() { 
    if (msg.value != 5 ether) throw; 
    _; 
}

function foo() CheckValue returns(returntype) {
    // function definiton
}

Hope this helps.

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.