2

I found that for a simple transaction, the UsedGas is constant value(i.e. 21000). Can it be modified when sending a transaction or configured somewhere? Thanks.

1
  • It's a part of the spec as far as I remember (you might even fin it in the official documentation). So if I remember correctly, then the answer is no. Jul 1, 2019 at 8:43

2 Answers 2

4

As @goodvibration mentioned, you can't modify this in the code of a client running publicly. (It'd lead to a protocol mismatch when your client tried to publicly broadcast anything - I think... )

If the scope of your question concerns your own private network, then you can edit the value and rebuild your client code.

The value is defined in protocol_params.go:

TxGas                 uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions.

(There's various associated test code that also hard-codes its own value, so you'd want to change those as well for completeness.)

Edit:

Thinking about this some more, you'd probably want to be careful that changing this doesn't completely screw up your network's gas pricing system, and the relative cost of sending a transaction vs. everything else...

0

It's unclear exactly what is being asked about here: the amount of gas sent with a transaction or the amount of gas required by it?

The amount of gas sent with a transaction can be modified when building the transaction to announce to the network. For example, if using web3, you can use the "gas" parameter, or when using MetaMask, you can click "Edit" just above the gas fee amount and then click Advanced to set the amount of gas to be included in the transaction.

If you include more than needed, you get the surplus refunded back, but if you include too much more (especially in excess of the dynamic per-block gas limit), miners might be less willing to include it in a block due to the maximum total gas per block.

The amount of gas used in any operation, as well as many other implementation details, is detailed in the Ethereum Yellow Paper (repository here).

1
  • I mean the actually used gas amount for a normal transaction. I also tried to modify the gas amount when sending transaction, but I found the finnally expended gas is always 21000.Thanks for you comments.
    – user53451
    Jul 2, 2019 at 1:38

Your Answer

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