0

Here is my code:

pragma solidity ^0.4.24;

contract TRY{  
    uint public temp=0;  
    function transfer_ether() public payable{  
        require(msg.value>=60);  
        temp=60;  
        msg.sender.transfer(msg.value-60);  
    }  
    function to_contract() public payable {  
        uint a=temp;  
        temp=0;  
        msg.sender.transfer(a);  
    }  
}

I deployed this code on test network on MyEtherWallet using Ganache.
Even when I enter a value less than 60.. it still doesn't revert as specified in the condition.
I cannot understood why is it happening.It would be helpful if someone explains the problem.

The solution to this problem: pragma solidity ^0.4.24;

contract TRY{

uint public temp=0;
uint public b=0;

function transfer_ether() public payable{
   require(msg.value>=60 ether);
        temp=msg.value;
         b=temp-(60 ether);
        temp=60 ether;
       msg.sender.transfer(b );
}

function to_contract() public payable {
    uint a=temp;
    temp=0;
    msg.sender.transfer(a);
}

}

  • how are you sending the value to the contract? If is via code just update your question, if not please consider that the value is expressed in wei not in ether – mirg Jun 18 '18 at 8:14
  • how to convert it to ether? in code. – Neha Jain Jun 18 '18 at 8:15
  • just change your condition require(msg.value >= 60 ether) – mirg Jun 18 '18 at 8:17
  • Moreover, you should use > instead of >= , because sending 0 ether is useless. – Florian Castelain Jun 18 '18 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.