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

  • 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, 2017 at 14:09

1 Answer 1


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

function foo() returns(return type) {
    if (msg.value != 5 ether) {
    // 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 and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.