0

This question has been asked a hundred times before. But with the change from v5 to v6 of the ethers.js library it has become unclear again how to do it. How can I estimate the cost of a transaction like a function call or contract deployment with ethers.js v6?

2 Answers 2

7

I had to figure it out too, but it's quite simple:

Ethers v5: myContract.estimateGas.myFunction(param1, param2);

Ethers v6: myContract.myFunction.estimateGas(param1, param2);

Turns out that the function name and .estimateGas have switched places; .estimateGas is now part of the function.

0

That's actually called gasLimit.

gasPrice is a different thing and means the amount of Wei they charge for 1 gas.

So if the transaction costs 2000 gas, and the gasPrice is 1, you have to pay at least 2000 gas.

In V6, the way you can get the gasPrice is:

(await provider.getFeeData()).gasPrice
1
  • You mean how I call it in the title? So to be more accurate the question should be: How to estimate the gas paid for a transaction?
    – rajohs
    Commented Jul 29 at 17:00

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.