Ethers.js – How to Estimate the Gas Price with Ethers.js v6

ethers.js

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?

Best Answer

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.

Related Topic