3

I am testing with function web3.eth.estimateGas and is not clear what Ether unit is returning.

Looks like it's gwei, but my final calculations don't match.

In my code, the EGAS returned is 84753. I think it is too little to be wei or gwei

How can I convert to wei the uint returned by estimateGas function?

2 Answers 2

1

I think I found the answer, but if you go to the source code "eth.py", function signature says it's returning "Wei":

def estimateGas(self, transaction: TxParams, block_identifier: BlockIdentifier=None) -> Wei:

This is actually very misleading. I tested this out. It returned "239231", but in what unit? You should interpret the number as follows:

gas_estimate
239231
gas_price = w3.eth.gasPrice
gas_price
5000000000000
gas_estimate_wei = gas_estimate * gas_price
gas_estimate_wei
1196155000000000000
gas_estimate_in_coin = gas_estimate_wei / (1000000000 * 1000000000)
gas_estimate_in_coin
1.196155

How you should interpret the numbers are as follows:

gas_estimate = 239231 units

gas_price = 5000,000,000,000 wei per unit

Or

gas_price = 5000 gwei per unit

So, "gas_estimate_in_coin" = 1.196155. Now, what "coin"? It depends on the chain you're interacting with. If you're interacting with CRONOS, that's 1.196155 CRO, which is about 49.9 cents in USD (CROUSDT = 0.4168 on 20220413)! On the other hand, on Ethereum mainnet, that's 1.196155 ETH, which changed everything!!!

References

(Wei, Gwei, ETH conversion)

https://web3py.readthedocs.io/en/stable/web3.eth.html?highlight=estimate_gas#web3.eth.Eth.estimate_gas

https://blog.oasis.app/gas-fees-a-small-guide/

https://www.thebalance.com/gwei-5194614

https://norman-lm-fung.medium.com/interact-with-cronos-single-usdc-lp-with-web3-py-1e14c62a0d9c

Similar question: Smart Contract - approve function: wad

0

It returns the gas limit, not the gas price. Gas limit is how many units of gas to use at most, and a unit of gas is your gas price.

5
  • I dont want to know te gasPrice. There is a web3js function for that. I need to know the real fee for a transaccion in Wei.
    – JTCon
    May 27, 2021 at 9:56
  • For that you need to use web3.eth.getGasPrice.
    – bru53001
    May 27, 2021 at 10:06
  • getGasPrice is a fixed value by the chain. I dont need that.
    – JTCon
    May 27, 2021 at 19:43
  • 3
    What? It literally returns the thing you want, the gas price in Wei. Also it is NOT a fixed value. Try multiplying estimateGas with getGasPrice for a transaction's total fee in wei.
    – bru53001
    May 28, 2021 at 3:47
  • this awnser is prerry correct to what was asked, why somebody downvoted it. estimateGas returns the gas limit, its unit is gas 'unit'. Sep 13, 2022 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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