0

In my transaction: gasPrice: 210000

blockHash: "0x69bd71736f2a5d2c83919a0de81a7de0b6b690bb6bdda3acff254d5c68f634bc",
blockNumber: 3178,
from: "0xc8caa71c16299b40b8579742a27ee53162886040",
gas: 2100000000,
gasPrice: 210000,

And the receipt: gasUsed: 72769

blockHash: "0x69bd71736f2a5d2c83919a0de81a7de0b6b690bb6bdda3acff254d5c68f634bc",
blockNumber: 3178,
contractAddress: null,
cumulativeGasUsed: 72769,
from: "0xc8caa71c16299b40b8579742a27ee53162886040",
gasUsed: 72769,

Is that means my total gas consumed = 72769 x 210000 = 15281490000 or 15GWei?

Can I safely assume gasUsed will remains the same if the execution condition (i.e. input parameters) remain the same? Even when I move my code from test node to the main ETH?

s k
  • 886
  • 1
  • 10
  • 22

1 Answers1

0

Can I safely assume gasUsed will remains the same if the execution condition

No. The gas may vary even calling the sane function. See Why transaction cost for same function differs even though content of function is same? and this.

AlsogasPrice changes dynamically. So you can not always send static gas price (210000). Sending less gas can result into failing of tx and sending less gas price may take a lot of time to get mined.

The better option is to use estimateGas to check for gas of your transactions and eth.gasPrice to estimate gas.

You can increase gas to more what you estimated because extra gas is refuded.

Prashant Prabhakar Singh
  • 8,026
  • 5
  • 40
  • 79
  • I am asking about the gasUsed in the transactionReceipt but not about the gasPrice – s k Jul 09 '18 at 09:03
  • gasUsed in tx receipt is the actual gas consumed. This also won't be constant. So may be this time gas consumed is 72769 but on subsequent calls this may vary. – Prashant Prabhakar Singh Jul 09 '18 at 09:39
  • I don't think so, since the gasUsed is lower than my gasPrice. – s k Jul 09 '18 at 11:12
  • @sk The term gasUsed refers to an entirely different parameter than gasPrice. While gasPrice is the price in wei you will pay to the miner for each unit of gas consumed, gasUsed indicates how many gas units were actually consumed by the transaction. You are probably mistaking gasPrice for gasLimit, which indicates the highest allowable gas consumed on your transaction. – Alex Papageorgiou Jul 09 '18 at 12:25
  • @Alex, if you read my original question carefully, I have never confused between gasPrice, gasLimit and gasUsed. It was Prashant – s k Jul 09 '18 at 14:39
  • I was trying to explain more than what u asked, so that future peoples visiting this question may be benefited. And for your question, I already answered in first line. NO. – Prashant Prabhakar Singh Jul 10 '18 at 04:12