4

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

Roman Frolov
  • 3,177
  • 2
  • 11
  • 29
Slava Fomin II
  • 307
  • 1
  • 2
  • 10

1 Answers1

14

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

gasLimit = Gtransaction + Gtxdatanonzero × dataByteLength

where:

Gtransaction = 21000 gas

Gtxdatanonzero = 68 gas

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
  • 307
  • 1
  • 2
  • 10