Why this transaction is revert?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I want to guarantee that user has enough Eth to execute back().



When you set little amount of eth in msg.value, there are no revert.
However, if you set almost of all Eth you have, the revert is occurred.



Even if you have enough Eth msg.value + Gas fee, the revert is occurred.



Why?



You can try this in Remix.



  1. Choose Environment

  2. Choose Account which has 100 Eth

  3. Set Value to 90 ether.

  4. Execute back and revert.

Why?



```solidity



pragma solidity ^0.4.24;

contract Back is Ownable

using SafeMath for uint;

modifier affordPay()
require(msg.sender.balance > msg.value, "You don't have enough eth!!");
_;


function back() external affordPay() payable
msg.sender.transfer(msg.value);





```










share|improve this question



























    up vote
    2
    down vote

    favorite












    I want to guarantee that user has enough Eth to execute back().



    When you set little amount of eth in msg.value, there are no revert.
    However, if you set almost of all Eth you have, the revert is occurred.



    Even if you have enough Eth msg.value + Gas fee, the revert is occurred.



    Why?



    You can try this in Remix.



    1. Choose Environment

    2. Choose Account which has 100 Eth

    3. Set Value to 90 ether.

    4. Execute back and revert.

    Why?



    ```solidity



    pragma solidity ^0.4.24;

    contract Back is Ownable

    using SafeMath for uint;

    modifier affordPay()
    require(msg.sender.balance > msg.value, "You don't have enough eth!!");
    _;


    function back() external affordPay() payable
    msg.sender.transfer(msg.value);





    ```










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I want to guarantee that user has enough Eth to execute back().



      When you set little amount of eth in msg.value, there are no revert.
      However, if you set almost of all Eth you have, the revert is occurred.



      Even if you have enough Eth msg.value + Gas fee, the revert is occurred.



      Why?



      You can try this in Remix.



      1. Choose Environment

      2. Choose Account which has 100 Eth

      3. Set Value to 90 ether.

      4. Execute back and revert.

      Why?



      ```solidity



      pragma solidity ^0.4.24;

      contract Back is Ownable

      using SafeMath for uint;

      modifier affordPay()
      require(msg.sender.balance > msg.value, "You don't have enough eth!!");
      _;


      function back() external affordPay() payable
      msg.sender.transfer(msg.value);





      ```










      share|improve this question















      I want to guarantee that user has enough Eth to execute back().



      When you set little amount of eth in msg.value, there are no revert.
      However, if you set almost of all Eth you have, the revert is occurred.



      Even if you have enough Eth msg.value + Gas fee, the revert is occurred.



      Why?



      You can try this in Remix.



      1. Choose Environment

      2. Choose Account which has 100 Eth

      3. Set Value to 90 ether.

      4. Execute back and revert.

      Why?



      ```solidity



      pragma solidity ^0.4.24;

      contract Back is Ownable

      using SafeMath for uint;

      modifier affordPay()
      require(msg.sender.balance > msg.value, "You don't have enough eth!!");
      _;


      function back() external affordPay() payable
      msg.sender.transfer(msg.value);





      ```







      solidity remix






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      Lauri Peltonen

      3,6342320




      3,6342320










      asked 2 hours ago









      R. M.

      133




      133




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          The type of check you are performing is not only useless but it's plain wrong.



          When a user issues a transaction with 90 Ethers as value, the 90 Ethers (plus gas) is immediately deducted from the account. The 90 Ethers becomes then visible in address(this).balance. Therefore, also, the sender's balance is also updated and can be seen with address(msg.sender).balance - it will have about 9.9999 Ethers (10 minus tx costs).



          So you don't need to check whether msg.value has an "acceptable" value - it will always contain a value which the user already committed into the transaction. Only if the transaction reverts the value is returned to the sender.






          share|improve this answer




















          • > the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
            – R. M.
            1 hour ago











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "642"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f61714%2fwhy-this-transaction-is-revert%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          The type of check you are performing is not only useless but it's plain wrong.



          When a user issues a transaction with 90 Ethers as value, the 90 Ethers (plus gas) is immediately deducted from the account. The 90 Ethers becomes then visible in address(this).balance. Therefore, also, the sender's balance is also updated and can be seen with address(msg.sender).balance - it will have about 9.9999 Ethers (10 minus tx costs).



          So you don't need to check whether msg.value has an "acceptable" value - it will always contain a value which the user already committed into the transaction. Only if the transaction reverts the value is returned to the sender.






          share|improve this answer




















          • > the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
            – R. M.
            1 hour ago















          up vote
          1
          down vote



          accepted










          The type of check you are performing is not only useless but it's plain wrong.



          When a user issues a transaction with 90 Ethers as value, the 90 Ethers (plus gas) is immediately deducted from the account. The 90 Ethers becomes then visible in address(this).balance. Therefore, also, the sender's balance is also updated and can be seen with address(msg.sender).balance - it will have about 9.9999 Ethers (10 minus tx costs).



          So you don't need to check whether msg.value has an "acceptable" value - it will always contain a value which the user already committed into the transaction. Only if the transaction reverts the value is returned to the sender.






          share|improve this answer




















          • > the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
            – R. M.
            1 hour ago













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          The type of check you are performing is not only useless but it's plain wrong.



          When a user issues a transaction with 90 Ethers as value, the 90 Ethers (plus gas) is immediately deducted from the account. The 90 Ethers becomes then visible in address(this).balance. Therefore, also, the sender's balance is also updated and can be seen with address(msg.sender).balance - it will have about 9.9999 Ethers (10 minus tx costs).



          So you don't need to check whether msg.value has an "acceptable" value - it will always contain a value which the user already committed into the transaction. Only if the transaction reverts the value is returned to the sender.






          share|improve this answer












          The type of check you are performing is not only useless but it's plain wrong.



          When a user issues a transaction with 90 Ethers as value, the 90 Ethers (plus gas) is immediately deducted from the account. The 90 Ethers becomes then visible in address(this).balance. Therefore, also, the sender's balance is also updated and can be seen with address(msg.sender).balance - it will have about 9.9999 Ethers (10 minus tx costs).



          So you don't need to check whether msg.value has an "acceptable" value - it will always contain a value which the user already committed into the transaction. Only if the transaction reverts the value is returned to the sender.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 1 hour ago









          Lauri Peltonen

          3,6342320




          3,6342320











          • > the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
            – R. M.
            1 hour ago

















          • > the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
            – R. M.
            1 hour ago
















          > the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
          – R. M.
          1 hour ago





          > the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
          – R. M.
          1 hour ago


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f61714%2fwhy-this-transaction-is-revert%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          Confectionery