How to charge percentage of transaction cost?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:
How important is it that $TERM is correct?
Negative Resistance
How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?
How to not starve gigantic beasts
"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"
Can I criticise the more senior developers around me for not writing clean code?
How can I practically buy stocks?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
What *exactly* is electrical current, voltage, and resistance?
What to do with someone that cheated their way through university and a PhD program?
Cayley's Matrix Notation
Are there moral objections to a life motivated purely by money? How to sway a person from this lifestyle?
Check if a string is entirely made of the same substring
I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?
How do I produce this Greek letter koppa: Ϟ in pdfLaTeX?
What does a straight horizontal line above a few notes, after a changed tempo mean?
How do I check if a string is entirely made of the same substring?
What is the most expensive material in the world that could be used to create Pun-Pun's lute?
Nails holding drywall
How to have a sharp product image?
Retract an already submitted recommendation letter (written for an undergrad student)
Was Dennis Ritchie being too modest in this quote about C and Pascal?
What is purpose of DB Browser(dbbrowser.aspx) under admin tool?
Why do real positive eigenvalues result in an unstable system? What about eigenvalues between 0 and 1? or 1?
How to charge percentage of transaction cost?
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:
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
add a comment |
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
add a comment |
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
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
solidity web3js contract-development gas gas-limit
edited Apr 22 at 20:04
shane
2,4624932
2,4624932
asked Apr 22 at 19:55
Jaren LJaren L
335
335
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
3
Psst,msg.gas
has been removed and replaced bygasleft
as per solidity.readthedocs.io/en/latest/…
– Lauri Peltonen
Apr 22 at 20:06
Ahh yes. Thank you.
– shane
Apr 22 at 20:06
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
Apr 22 at 22:55
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
3
Psst,msg.gas
has been removed and replaced bygasleft
as per solidity.readthedocs.io/en/latest/…
– Lauri Peltonen
Apr 22 at 20:06
Ahh yes. Thank you.
– shane
Apr 22 at 20:06
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
Apr 22 at 22:55
add a comment |
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.
3
Psst,msg.gas
has been removed and replaced bygasleft
as per solidity.readthedocs.io/en/latest/…
– Lauri Peltonen
Apr 22 at 20:06
Ahh yes. Thank you.
– shane
Apr 22 at 20:06
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
Apr 22 at 22:55
add a comment |
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.
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.
edited Apr 22 at 20:07
answered Apr 22 at 20:03
shaneshane
2,4624932
2,4624932
3
Psst,msg.gas
has been removed and replaced bygasleft
as per solidity.readthedocs.io/en/latest/…
– Lauri Peltonen
Apr 22 at 20:06
Ahh yes. Thank you.
– shane
Apr 22 at 20:06
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
Apr 22 at 22:55
add a comment |
3
Psst,msg.gas
has been removed and replaced bygasleft
as per solidity.readthedocs.io/en/latest/…
– Lauri Peltonen
Apr 22 at 20:06
Ahh yes. Thank you.
– shane
Apr 22 at 20:06
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
Apr 22 at 22:55
3
3
Psst,
msg.gas
has been removed and replaced by gasleft
as per solidity.readthedocs.io/en/latest/…– Lauri Peltonen
Apr 22 at 20:06
Psst,
msg.gas
has been removed and replaced by gasleft
as per solidity.readthedocs.io/en/latest/…– Lauri Peltonen
Apr 22 at 20:06
Ahh yes. Thank you.
– shane
Apr 22 at 20:06
Ahh yes. Thank you.
– shane
Apr 22 at 20:06
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
Apr 22 at 22:55
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
Apr 22 at 22:55
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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