Unable to match calculated “gas used” value using Solidity IDE to the etherscan explorer “Gas Used By Transaction”










0















I am trying find the gas used by the transaction when a method is clicked in the remix solidity IDE. my code is as below. Value I am getting in the gasUsed variable is different to the value that is being shown on the etherscan explorer for this transaction. It would be helpful if someone helps me in correcting my code.



pragma solidity ^0.4.22;

contract id

uint public id;
uint public senderValue;
uint256 public gasUsed;

constructor() public
senderValue= msg.sender;


function setId(uint _id) public
uint256 gasInitial = gasleft();
id= _id;
setGasUsed(gasInitial - gasleft());


function setGasUsed(uint256 _gasUsed) private
gasUsed = _gasUsed;












share|improve this question


























    0















    I am trying find the gas used by the transaction when a method is clicked in the remix solidity IDE. my code is as below. Value I am getting in the gasUsed variable is different to the value that is being shown on the etherscan explorer for this transaction. It would be helpful if someone helps me in correcting my code.



    pragma solidity ^0.4.22;

    contract id

    uint public id;
    uint public senderValue;
    uint256 public gasUsed;

    constructor() public
    senderValue= msg.sender;


    function setId(uint _id) public
    uint256 gasInitial = gasleft();
    id= _id;
    setGasUsed(gasInitial - gasleft());


    function setGasUsed(uint256 _gasUsed) private
    gasUsed = _gasUsed;












    share|improve this question
























      0












      0








      0








      I am trying find the gas used by the transaction when a method is clicked in the remix solidity IDE. my code is as below. Value I am getting in the gasUsed variable is different to the value that is being shown on the etherscan explorer for this transaction. It would be helpful if someone helps me in correcting my code.



      pragma solidity ^0.4.22;

      contract id

      uint public id;
      uint public senderValue;
      uint256 public gasUsed;

      constructor() public
      senderValue= msg.sender;


      function setId(uint _id) public
      uint256 gasInitial = gasleft();
      id= _id;
      setGasUsed(gasInitial - gasleft());


      function setGasUsed(uint256 _gasUsed) private
      gasUsed = _gasUsed;












      share|improve this question














      I am trying find the gas used by the transaction when a method is clicked in the remix solidity IDE. my code is as below. Value I am getting in the gasUsed variable is different to the value that is being shown on the etherscan explorer for this transaction. It would be helpful if someone helps me in correcting my code.



      pragma solidity ^0.4.22;

      contract id

      uint public id;
      uint public senderValue;
      uint256 public gasUsed;

      constructor() public
      senderValue= msg.sender;


      function setId(uint _id) public
      uint256 gasInitial = gasleft();
      id= _id;
      setGasUsed(gasInitial - gasleft());


      function setGasUsed(uint256 _gasUsed) private
      gasUsed = _gasUsed;









      ethereum solidity remix etherscan






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 5:10









      user7481861user7481861

      123




      123






















          2 Answers
          2






          active

          oldest

          votes


















          1














          The value of "gas used" in remix IDE is Execution Cost and the value of "Gas Used By Transaction" in etherscan is "Transaction cost".



          Execution Costs are based on the cost of computational operations which are executed as a result of the transaction.



          Transaction Costs are always based on the cost of which type of data you will send to blockchain. This depends on,



          1. base cost of transaction (21000 gas)

          2. the cost of a contract deployment (32000 gas)

          3. the cost for every zero byte of data or code for a transaction.

          4. the cost of every non-zero byte of data or code for a transaction.

          You can understand easily by this image enter image description here



          Hope this answer clear your doubt.






          share|improve this answer























          • I got it. So is it possible to get the value of transaction cost in the remix code anyhow?

            – user7481861
            Nov 13 '18 at 14:22











          • No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.

            – Mahesh Rajput
            Nov 14 '18 at 5:09


















          0














          Good question, I tested too. It means that, gasleft() equals 20020 gas before executing gasUsed2 = gasleft();. And after executing gasUsed2 = gasleft();, gasleft() = 0



          test() transaction costs 61475 gas



          gasUsed1 equals 40033 gas



          gasUsed2 equals 20020 gas



          pragma solidity ^0.4.22;

          contract id
          uint256 public gasUsed1;
          uint256 public gasUsed2;

          function test() public
          gasUsed1 = gasleft();
          gasUsed2 = gasleft();







          share|improve this answer























          • yes exactly. did you get to know how to match it?

            – user7481861
            Nov 13 '18 at 14:19










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fstackoverflow.com%2fquestions%2f53274209%2funable-to-match-calculated-gas-used-value-using-solidity-ide-to-the-etherscan%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The value of "gas used" in remix IDE is Execution Cost and the value of "Gas Used By Transaction" in etherscan is "Transaction cost".



          Execution Costs are based on the cost of computational operations which are executed as a result of the transaction.



          Transaction Costs are always based on the cost of which type of data you will send to blockchain. This depends on,



          1. base cost of transaction (21000 gas)

          2. the cost of a contract deployment (32000 gas)

          3. the cost for every zero byte of data or code for a transaction.

          4. the cost of every non-zero byte of data or code for a transaction.

          You can understand easily by this image enter image description here



          Hope this answer clear your doubt.






          share|improve this answer























          • I got it. So is it possible to get the value of transaction cost in the remix code anyhow?

            – user7481861
            Nov 13 '18 at 14:22











          • No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.

            – Mahesh Rajput
            Nov 14 '18 at 5:09















          1














          The value of "gas used" in remix IDE is Execution Cost and the value of "Gas Used By Transaction" in etherscan is "Transaction cost".



          Execution Costs are based on the cost of computational operations which are executed as a result of the transaction.



          Transaction Costs are always based on the cost of which type of data you will send to blockchain. This depends on,



          1. base cost of transaction (21000 gas)

          2. the cost of a contract deployment (32000 gas)

          3. the cost for every zero byte of data or code for a transaction.

          4. the cost of every non-zero byte of data or code for a transaction.

          You can understand easily by this image enter image description here



          Hope this answer clear your doubt.






          share|improve this answer























          • I got it. So is it possible to get the value of transaction cost in the remix code anyhow?

            – user7481861
            Nov 13 '18 at 14:22











          • No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.

            – Mahesh Rajput
            Nov 14 '18 at 5:09













          1












          1








          1







          The value of "gas used" in remix IDE is Execution Cost and the value of "Gas Used By Transaction" in etherscan is "Transaction cost".



          Execution Costs are based on the cost of computational operations which are executed as a result of the transaction.



          Transaction Costs are always based on the cost of which type of data you will send to blockchain. This depends on,



          1. base cost of transaction (21000 gas)

          2. the cost of a contract deployment (32000 gas)

          3. the cost for every zero byte of data or code for a transaction.

          4. the cost of every non-zero byte of data or code for a transaction.

          You can understand easily by this image enter image description here



          Hope this answer clear your doubt.






          share|improve this answer













          The value of "gas used" in remix IDE is Execution Cost and the value of "Gas Used By Transaction" in etherscan is "Transaction cost".



          Execution Costs are based on the cost of computational operations which are executed as a result of the transaction.



          Transaction Costs are always based on the cost of which type of data you will send to blockchain. This depends on,



          1. base cost of transaction (21000 gas)

          2. the cost of a contract deployment (32000 gas)

          3. the cost for every zero byte of data or code for a transaction.

          4. the cost of every non-zero byte of data or code for a transaction.

          You can understand easily by this image enter image description here



          Hope this answer clear your doubt.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 10:01









          Mahesh RajputMahesh Rajput

          2959




          2959












          • I got it. So is it possible to get the value of transaction cost in the remix code anyhow?

            – user7481861
            Nov 13 '18 at 14:22











          • No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.

            – Mahesh Rajput
            Nov 14 '18 at 5:09

















          • I got it. So is it possible to get the value of transaction cost in the remix code anyhow?

            – user7481861
            Nov 13 '18 at 14:22











          • No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.

            – Mahesh Rajput
            Nov 14 '18 at 5:09
















          I got it. So is it possible to get the value of transaction cost in the remix code anyhow?

          – user7481861
          Nov 13 '18 at 14:22





          I got it. So is it possible to get the value of transaction cost in the remix code anyhow?

          – user7481861
          Nov 13 '18 at 14:22













          No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.

          – Mahesh Rajput
          Nov 14 '18 at 5:09





          No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.

          – Mahesh Rajput
          Nov 14 '18 at 5:09













          0














          Good question, I tested too. It means that, gasleft() equals 20020 gas before executing gasUsed2 = gasleft();. And after executing gasUsed2 = gasleft();, gasleft() = 0



          test() transaction costs 61475 gas



          gasUsed1 equals 40033 gas



          gasUsed2 equals 20020 gas



          pragma solidity ^0.4.22;

          contract id
          uint256 public gasUsed1;
          uint256 public gasUsed2;

          function test() public
          gasUsed1 = gasleft();
          gasUsed2 = gasleft();







          share|improve this answer























          • yes exactly. did you get to know how to match it?

            – user7481861
            Nov 13 '18 at 14:19















          0














          Good question, I tested too. It means that, gasleft() equals 20020 gas before executing gasUsed2 = gasleft();. And after executing gasUsed2 = gasleft();, gasleft() = 0



          test() transaction costs 61475 gas



          gasUsed1 equals 40033 gas



          gasUsed2 equals 20020 gas



          pragma solidity ^0.4.22;

          contract id
          uint256 public gasUsed1;
          uint256 public gasUsed2;

          function test() public
          gasUsed1 = gasleft();
          gasUsed2 = gasleft();







          share|improve this answer























          • yes exactly. did you get to know how to match it?

            – user7481861
            Nov 13 '18 at 14:19













          0












          0








          0







          Good question, I tested too. It means that, gasleft() equals 20020 gas before executing gasUsed2 = gasleft();. And after executing gasUsed2 = gasleft();, gasleft() = 0



          test() transaction costs 61475 gas



          gasUsed1 equals 40033 gas



          gasUsed2 equals 20020 gas



          pragma solidity ^0.4.22;

          contract id
          uint256 public gasUsed1;
          uint256 public gasUsed2;

          function test() public
          gasUsed1 = gasleft();
          gasUsed2 = gasleft();







          share|improve this answer













          Good question, I tested too. It means that, gasleft() equals 20020 gas before executing gasUsed2 = gasleft();. And after executing gasUsed2 = gasleft();, gasleft() = 0



          test() transaction costs 61475 gas



          gasUsed1 equals 40033 gas



          gasUsed2 equals 20020 gas



          pragma solidity ^0.4.22;

          contract id
          uint256 public gasUsed1;
          uint256 public gasUsed2;

          function test() public
          gasUsed1 = gasleft();
          gasUsed2 = gasleft();








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 7:39









          EgorEgor

          517112




          517112












          • yes exactly. did you get to know how to match it?

            – user7481861
            Nov 13 '18 at 14:19

















          • yes exactly. did you get to know how to match it?

            – user7481861
            Nov 13 '18 at 14:19
















          yes exactly. did you get to know how to match it?

          – user7481861
          Nov 13 '18 at 14:19





          yes exactly. did you get to know how to match it?

          – user7481861
          Nov 13 '18 at 14:19

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274209%2funable-to-match-calculated-gas-used-value-using-solidity-ide-to-the-etherscan%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto