How do you calculate gas limit for ether transaction with data in Ethereum?

by Slava Fomin II   Last Updated February 12, 2018 18:28 PM

What is the correct algorithm to calculate gas limit for ether transaction with data in Ethereum?



Answers 1


According to Ethereum Whitepapper, in order to calculate gas limit for ether transaction with non-zero data you will need to use the following formula:

gasLimit = Gtransaction + Gtxdatanonzero * dataByteLength,

where:

Gtransaction = 21000
Gtxdatanonzero = 68

dataByteLength — your data size in bytes

So, the final formula would look like this:

gasLimit = 21000 + 68 * dataByteLength.

If your data has 10 bytes, the gas limit would be:

gasLimit = 21000 + 68 * 10 = 21000 + 680 = 21680

Slava Fomin II
Slava Fomin II
February 12, 2018 17:47 PM

Related Questions


Updated October 28, 2018 20:28 PM

Updated October 18, 2017 07:28 AM

Updated January 19, 2018 15:28 PM

Updated June 26, 2019 17:28 PM

Updated September 24, 2018 22:28 PM