4

Can I restrict transaction fee (gas price) for the payable method of the crowdsale contract. And if I can, how?

And one more question, if I restrict fee and call revert() - this transaction will be declined in the memepool and will be not mined at all, or not?

Thanks!

1 Answer 1

4

There's no way to stop a transaction from being mined, but you can check the gas price using tx.gasprice and not process transactions that are above a certain gas price, e.g.

function() payable {
    require(tx.gasprice<30000000000); //30000000000 is 30 gwei
                                      //if gas price is higher than it, the tx will fail
    doOtherProcessing();
}

Note that this will refund any unused gas. If you change require to assert, then it wont refund the unused gas.

2
  • But even in this case transaction will be mined but as failed and sender spent gas for it? Commented Jan 30, 2018 at 0:11
  • 1
    Yes, the transaction will be mined and will fail due to a revert opcode. The sender will pay for the already-used gas.
    – user19510
    Commented Jan 30, 2018 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.