Sending a transaction - can I assume that when the 'data' field is missing, the 'gas' field should always be 21000?

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











up vote
1
down vote

favorite












I have implemented a function for transferring ETH from my account to another account:



async function transfer(to, value) 
let options =
from : PUBLIC_ADDRESS,
to : to,
value: value
;
options.gas = await web3.eth.estimateGas(options);
let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);



This is purely for ETH transfer; I am not trying to invoke any smart contract function, so I can omit the data field from the options object.



I've noticed that web3.eth.estimateGas(options) always returns 21000.



Can I count on that, and simplify my code to:



 let options = 
from : PUBLIC_ADDR,
to : to,
value: value,
gas : 21000
;


?



Thanks










share|improve this question

























    up vote
    1
    down vote

    favorite












    I have implemented a function for transferring ETH from my account to another account:



    async function transfer(to, value) 
    let options =
    from : PUBLIC_ADDRESS,
    to : to,
    value: value
    ;
    options.gas = await web3.eth.estimateGas(options);
    let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
    return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);



    This is purely for ETH transfer; I am not trying to invoke any smart contract function, so I can omit the data field from the options object.



    I've noticed that web3.eth.estimateGas(options) always returns 21000.



    Can I count on that, and simplify my code to:



     let options = 
    from : PUBLIC_ADDR,
    to : to,
    value: value,
    gas : 21000
    ;


    ?



    Thanks










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have implemented a function for transferring ETH from my account to another account:



      async function transfer(to, value) 
      let options =
      from : PUBLIC_ADDRESS,
      to : to,
      value: value
      ;
      options.gas = await web3.eth.estimateGas(options);
      let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
      return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);



      This is purely for ETH transfer; I am not trying to invoke any smart contract function, so I can omit the data field from the options object.



      I've noticed that web3.eth.estimateGas(options) always returns 21000.



      Can I count on that, and simplify my code to:



       let options = 
      from : PUBLIC_ADDR,
      to : to,
      value: value,
      gas : 21000
      ;


      ?



      Thanks










      share|improve this question













      I have implemented a function for transferring ETH from my account to another account:



      async function transfer(to, value) 
      let options =
      from : PUBLIC_ADDRESS,
      to : to,
      value: value
      ;
      options.gas = await web3.eth.estimateGas(options);
      let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
      return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);



      This is purely for ETH transfer; I am not trying to invoke any smart contract function, so I can omit the data field from the options object.



      I've noticed that web3.eth.estimateGas(options) always returns 21000.



      Can I count on that, and simplify my code to:



       let options = 
      from : PUBLIC_ADDR,
      to : to,
      value: value,
      gas : 21000
      ;


      ?



      Thanks







      web3js transactions gas gas-estimate






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 5 hours ago









      goodvibration

      1,972519




      1,972519




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          If the to address is not a smart contract, then yes. This is the standard gas cost of a simple ether transfer.



          If the to address is a smart contract, even if you're not sending anything in the data field, a different gas amount could be consumed.






          share|improve this answer




















          • Indeed, my to address is not a smart contract, hence the data field is empty (and I now understand that an empty data field doesn't necessarily imply a non-contract to address). Thank you very much!!!
            – goodvibration
            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: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          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%2f60937%2fsending-a-transaction-can-i-assume-that-when-the-data-field-is-missing-the%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
          2
          down vote



          accepted










          If the to address is not a smart contract, then yes. This is the standard gas cost of a simple ether transfer.



          If the to address is a smart contract, even if you're not sending anything in the data field, a different gas amount could be consumed.






          share|improve this answer




















          • Indeed, my to address is not a smart contract, hence the data field is empty (and I now understand that an empty data field doesn't necessarily imply a non-contract to address). Thank you very much!!!
            – goodvibration
            1 hour ago














          up vote
          2
          down vote



          accepted










          If the to address is not a smart contract, then yes. This is the standard gas cost of a simple ether transfer.



          If the to address is a smart contract, even if you're not sending anything in the data field, a different gas amount could be consumed.






          share|improve this answer




















          • Indeed, my to address is not a smart contract, hence the data field is empty (and I now understand that an empty data field doesn't necessarily imply a non-contract to address). Thank you very much!!!
            – goodvibration
            1 hour ago












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          If the to address is not a smart contract, then yes. This is the standard gas cost of a simple ether transfer.



          If the to address is a smart contract, even if you're not sending anything in the data field, a different gas amount could be consumed.






          share|improve this answer












          If the to address is not a smart contract, then yes. This is the standard gas cost of a simple ether transfer.



          If the to address is a smart contract, even if you're not sending anything in the data field, a different gas amount could be consumed.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          smarx

          16.6k1615




          16.6k1615











          • Indeed, my to address is not a smart contract, hence the data field is empty (and I now understand that an empty data field doesn't necessarily imply a non-contract to address). Thank you very much!!!
            – goodvibration
            1 hour ago
















          • Indeed, my to address is not a smart contract, hence the data field is empty (and I now understand that an empty data field doesn't necessarily imply a non-contract to address). Thank you very much!!!
            – goodvibration
            1 hour ago















          Indeed, my to address is not a smart contract, hence the data field is empty (and I now understand that an empty data field doesn't necessarily imply a non-contract to address). Thank you very much!!!
          – goodvibration
          1 hour ago




          Indeed, my to address is not a smart contract, hence the data field is empty (and I now understand that an empty data field doesn't necessarily imply a non-contract to address). Thank you very much!!!
          – goodvibration
          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%2f60937%2fsending-a-transaction-can-i-assume-that-when-the-data-field-is-missing-the%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          Installing NextGIS Connect into QGIS 3?

          One-line joke