The question is above. In reality, I see some (small) fluctuations. However, upon reading the documents, I think the gas should be constant, provided that the transaction is exactly the same. Which is true? Do I miss something?


The amount of gas depends on the size of tx's data. The high gasPrice tx has priority to be mined, and miner will drop non-local transactions under their own minimal accepted gas price. The amount of gas will be computed by IntrinsicGas method of st_transaction.go source file, As follows:

func IntrinsicGas(data []byte, contractCreation, homestead bool) *big.Int {
  igas := new(big.Int)
  if contractCreation && homestead {
  } else {
  if len(data) > 0 {
    var nz int64
    for _, byt := range data {
      if byt != 0 {
    m := big.NewInt(nz)
    m.Mul(m, new(big.Int).SetUint64(params.TxDataNonZeroGas))
    igas.Add(igas, m)
    m.SetInt64(int64(len(data)) - nz)
    m.Mul(m, new(big.Int).SetUint64(params.TxDataZeroGas))
    igas.Add(igas, m)
  return igas

Hope this helps ~

| improve this answer | |
  • How about functions having loops? Then, how is the gas represented on the txn data? Perhaps this is just the intrinsic gas, and there is another amount of gas cost by the txn? – Vincent J. Ruan Aug 7 '17 at 1:18
  • 1
    Yes, you are right. For every type vm instruction，there is different gas cost. you can view 'Assembly' for contract compiled on remix. In api.go source file, EstimateGas method would estimate gas cost, you can view estimate logic. The vm every instruction op cost had be defined on jump_table.go file.For instance, add op will cost 3 gas. – BinGoBinBin Aug 7 '17 at 3:20

The amount of gas for a particular transaction is fixed since the cost is based on the Ethereum virtual machine (EVM) operations performed in the transaction and this is deterministic. However, one must pay for the gas used and this amount is up to the sender. The amount per unit of gas is known as the gas price. Thus, the price of a particular transaction is gas price x gas used. That is, the cost of the transaction, even with the same code executed, can be vary, within limits (see below), and is set by the transaction sender.

The miner chooses which transaction(s) to include in a block and one heuristic they may rely on is the gas price; presumably, the higher the gas price, the more likely the transaction will be included. If the gas price for a particular transaction is too low, the miner may simply ignore it. Thus, there is a practical lower bound to the transaction price. I'm still looking for an answer on whether there's an upper limit on gas price.

| improve this answer | |
  • I think there is no implemented upper limit. A practical upper limit does exist, it's based on clients (through contracts) and miners (through discarding txns having suspiciously high gas price). – Vincent J. Ruan Aug 7 '17 at 2:12

Your Answer

