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.

  • 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. – goodvibration Jul 1 '19 at 8:43

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.)


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...


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).

  • 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. – Ntydrm Jul 2 '19 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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