How to charge percentage of transaction cost? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Error: “message”:“function ”Ballot“ arguments must include ”proposalNames“”}Solidity browser compiler function gas cost vs actual transaction costEstimating gas cost of a transaction function with web3Transaction write limitshow to estimate gas cost?How is Ethereum Wallet's transaction cost calculated?Web3 sendSignedTransaction Transaction costInternal transaction cost vs externalUntransferable token percentageSolidity Language: Fractional Percentage Numbers:

Why do people think Winterfell crypts is the safest place for women, children & old people?

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

If gravity precedes the formation of a solar system, where did the mass come from that caused the gravity?

Is Bran literally the world's memory?

What is the evidence that custom checks in Northern Ireland are going to result in violence?

2 sample t test for sample sizes - 30,000 and 150,000

Coin Game with infinite paradox

Will I be more secure with my own router behind my ISP's router?

Why not use the yoke to control yaw, as well as pitch and roll?

Weaponising the Grasp-at-a-Distance spell

Putting Ant-Man on house arrest

Does traveling In The United States require a passport or can I use my green card if not a US citizen?

What is the ongoing value of the Kanban board to the developers as opposed to management

Recursive calls to a function - why is the address of the parameter passed to it lowering with each call?

A journey... into the MIND

How do I deal with an erroneously large refund?

Are Flameskulls resistant to magical piercing damage?

Can the van der Waals coefficients be negative in the van der Waals equation for real gases?

Meaning of "Not holding on that level of emuna/bitachon"

When speaking, how do you change your mind mid-sentence?

Compiling and throwing simple dynamic exceptions at runtime for JVM

Lights are flickering on and off after accidentally bumping into light switch

Can this water damage be explained by lack of gutters and grading issues?

Why does my GNOME settings mention "Moto C Plus"?



How to charge percentage of transaction cost?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Error: “message”:“function ”Ballot“ arguments must include ”proposalNames“”}Solidity browser compiler function gas cost vs actual transaction costEstimating gas cost of a transaction function with web3Transaction write limitshow to estimate gas cost?How is Ethereum Wallet's transaction cost calculated?Web3 sendSignedTransaction Transaction costInternal transaction cost vs externalUntransferable token percentageSolidity Language: Fractional Percentage Numbers:










1















Example:



uint public createPostCost = 0.0003 ether;

function createPost(bytes32 _post)
public payable
require(msg.value >= createPostCost);
Post memory newPost;
newPost.post = _post;



Within a discussion forum dapp, the current implementation charges users a set fee per post created. I would like the charge to be dynamic, say 10% of the gas cost of the transaction. Is this possible to implement in the contract? Or is this something for front-end web3 to handle?










share|improve this question




























    1















    Example:



    uint public createPostCost = 0.0003 ether;

    function createPost(bytes32 _post)
    public payable
    require(msg.value >= createPostCost);
    Post memory newPost;
    newPost.post = _post;



    Within a discussion forum dapp, the current implementation charges users a set fee per post created. I would like the charge to be dynamic, say 10% of the gas cost of the transaction. Is this possible to implement in the contract? Or is this something for front-end web3 to handle?










    share|improve this question


























      1












      1








      1








      Example:



      uint public createPostCost = 0.0003 ether;

      function createPost(bytes32 _post)
      public payable
      require(msg.value >= createPostCost);
      Post memory newPost;
      newPost.post = _post;



      Within a discussion forum dapp, the current implementation charges users a set fee per post created. I would like the charge to be dynamic, say 10% of the gas cost of the transaction. Is this possible to implement in the contract? Or is this something for front-end web3 to handle?










      share|improve this question
















      Example:



      uint public createPostCost = 0.0003 ether;

      function createPost(bytes32 _post)
      public payable
      require(msg.value >= createPostCost);
      Post memory newPost;
      newPost.post = _post;



      Within a discussion forum dapp, the current implementation charges users a set fee per post created. I would like the charge to be dynamic, say 10% of the gas cost of the transaction. Is this possible to implement in the contract? Or is this something for front-end web3 to handle?







      solidity web3js contract-development gas gas-limit






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 7 hours ago









      shane

      2,4524832




      2,4524832










      asked 7 hours ago









      Jaren LJaren L

      335




      335




















          1 Answer
          1






          active

          oldest

          votes


















          3














          Yes, you can let the charge be a function of the gas of the transaction. You would do something like this:



          uint256 charge = gasleft() / 10;



          This is sensitive and you should know that gasleft() returns the amount of gas available at that point in the execution. Therefore, if you call gasleft() at the beginning of a function, the number will be higher than at the end of the function.



          Additionally, someone may send a lot of unnecessary gas, so they could end up paying a lot.



          My opinion is that it is best to handle this on the front-end.



          Edit



          If you are trying to take into account the gasPrice, you can use tx.gasprice. See here for more information.






          share|improve this answer




















          • 3





            Psst, msg.gas has been removed and replaced by gasleft as per solidity.readthedocs.io/en/latest/…

            – Lauri Peltonen
            7 hours ago











          • Ahh yes. Thank you.

            – shane
            7 hours ago











          • Ah that makes sense. If I made a require to check the msg.value >= 10% of tx.gasprice, would that work? Would there be discrepancies between generating the web3 function call price + value and the contract value?

            – Jaren L
            4 hours 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',
          autoActivateHeartbeat: false,
          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%2f69960%2fhow-to-charge-percentage-of-transaction-cost%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Yes, you can let the charge be a function of the gas of the transaction. You would do something like this:



          uint256 charge = gasleft() / 10;



          This is sensitive and you should know that gasleft() returns the amount of gas available at that point in the execution. Therefore, if you call gasleft() at the beginning of a function, the number will be higher than at the end of the function.



          Additionally, someone may send a lot of unnecessary gas, so they could end up paying a lot.



          My opinion is that it is best to handle this on the front-end.



          Edit



          If you are trying to take into account the gasPrice, you can use tx.gasprice. See here for more information.






          share|improve this answer




















          • 3





            Psst, msg.gas has been removed and replaced by gasleft as per solidity.readthedocs.io/en/latest/…

            – Lauri Peltonen
            7 hours ago











          • Ahh yes. Thank you.

            – shane
            7 hours ago











          • Ah that makes sense. If I made a require to check the msg.value >= 10% of tx.gasprice, would that work? Would there be discrepancies between generating the web3 function call price + value and the contract value?

            – Jaren L
            4 hours ago
















          3














          Yes, you can let the charge be a function of the gas of the transaction. You would do something like this:



          uint256 charge = gasleft() / 10;



          This is sensitive and you should know that gasleft() returns the amount of gas available at that point in the execution. Therefore, if you call gasleft() at the beginning of a function, the number will be higher than at the end of the function.



          Additionally, someone may send a lot of unnecessary gas, so they could end up paying a lot.



          My opinion is that it is best to handle this on the front-end.



          Edit



          If you are trying to take into account the gasPrice, you can use tx.gasprice. See here for more information.






          share|improve this answer




















          • 3





            Psst, msg.gas has been removed and replaced by gasleft as per solidity.readthedocs.io/en/latest/…

            – Lauri Peltonen
            7 hours ago











          • Ahh yes. Thank you.

            – shane
            7 hours ago











          • Ah that makes sense. If I made a require to check the msg.value >= 10% of tx.gasprice, would that work? Would there be discrepancies between generating the web3 function call price + value and the contract value?

            – Jaren L
            4 hours ago














          3












          3








          3







          Yes, you can let the charge be a function of the gas of the transaction. You would do something like this:



          uint256 charge = gasleft() / 10;



          This is sensitive and you should know that gasleft() returns the amount of gas available at that point in the execution. Therefore, if you call gasleft() at the beginning of a function, the number will be higher than at the end of the function.



          Additionally, someone may send a lot of unnecessary gas, so they could end up paying a lot.



          My opinion is that it is best to handle this on the front-end.



          Edit



          If you are trying to take into account the gasPrice, you can use tx.gasprice. See here for more information.






          share|improve this answer















          Yes, you can let the charge be a function of the gas of the transaction. You would do something like this:



          uint256 charge = gasleft() / 10;



          This is sensitive and you should know that gasleft() returns the amount of gas available at that point in the execution. Therefore, if you call gasleft() at the beginning of a function, the number will be higher than at the end of the function.



          Additionally, someone may send a lot of unnecessary gas, so they could end up paying a lot.



          My opinion is that it is best to handle this on the front-end.



          Edit



          If you are trying to take into account the gasPrice, you can use tx.gasprice. See here for more information.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 7 hours ago

























          answered 7 hours ago









          shaneshane

          2,4524832




          2,4524832







          • 3





            Psst, msg.gas has been removed and replaced by gasleft as per solidity.readthedocs.io/en/latest/…

            – Lauri Peltonen
            7 hours ago











          • Ahh yes. Thank you.

            – shane
            7 hours ago











          • Ah that makes sense. If I made a require to check the msg.value >= 10% of tx.gasprice, would that work? Would there be discrepancies between generating the web3 function call price + value and the contract value?

            – Jaren L
            4 hours ago













          • 3





            Psst, msg.gas has been removed and replaced by gasleft as per solidity.readthedocs.io/en/latest/…

            – Lauri Peltonen
            7 hours ago











          • Ahh yes. Thank you.

            – shane
            7 hours ago











          • Ah that makes sense. If I made a require to check the msg.value >= 10% of tx.gasprice, would that work? Would there be discrepancies between generating the web3 function call price + value and the contract value?

            – Jaren L
            4 hours ago








          3




          3





          Psst, msg.gas has been removed and replaced by gasleft as per solidity.readthedocs.io/en/latest/…

          – Lauri Peltonen
          7 hours ago





          Psst, msg.gas has been removed and replaced by gasleft as per solidity.readthedocs.io/en/latest/…

          – Lauri Peltonen
          7 hours ago













          Ahh yes. Thank you.

          – shane
          7 hours ago





          Ahh yes. Thank you.

          – shane
          7 hours ago













          Ah that makes sense. If I made a require to check the msg.value >= 10% of tx.gasprice, would that work? Would there be discrepancies between generating the web3 function call price + value and the contract value?

          – Jaren L
          4 hours ago






          Ah that makes sense. If I made a require to check the msg.value >= 10% of tx.gasprice, would that work? Would there be discrepancies between generating the web3 function call price + value and the contract value?

          – Jaren L
          4 hours ago


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Ethereum Stack Exchange!


          • 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%2fethereum.stackexchange.com%2fquestions%2f69960%2fhow-to-charge-percentage-of-transaction-cost%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







          Popular posts from this blog

          How to create a command for the “strange m” symbol in latex? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How do you make your own symbol when Detexify fails?Writing bold small caps with mathpazo packageplus-minus symbol with parenthesis around the minus signGreek character in Beamer document titleHow to create dashed right arrow over symbol?Currency symbol: Turkish LiraDouble prec as a single symbol?Plus Sign Too Big; How to Call adfbullet?Is there a TeX macro for three-legged pi?How do I get my integral-like symbol to align like the integral?How to selectively substitute a letter with another symbol representing the same letterHow do I generate a less than symbol and vertical bar that are the same height?

          Българска екзархия Съдържание История | Български екзарси | Вижте също | Външни препратки | Литература | Бележки | НавигацияУстав за управлението на българската екзархия. Цариград, 1870Слово на Ловешкия митрополит Иларион при откриването на Българския народен събор в Цариград на 23. II. 1870 г.Българската правда и гръцката кривда. От С. М. (= Софийски Мелетий). Цариград, 1872Предстоятели на Българската екзархияПодмененият ВеликденИнформационна агенция „Фокус“Димитър Ризов. Българите в техните исторически, етнографически и политически граници (Атлас съдържащ 40 карти). Berlin, Königliche Hoflithographie, Hof-Buch- und -Steindruckerei Wilhelm Greve, 1917Report of the International Commission to Inquire into the Causes and Conduct of the Balkan Wars

          Category:Tremithousa Media in category "Tremithousa"Navigation menuUpload media34° 49′ 02.7″ N, 32° 26′ 37.32″ EOpenStreetMapGoogle EarthProximityramaReasonatorScholiaStatisticsWikiShootMe