Let's say you have a function in your smart contract, like:
function saveUser(address newUser) public {
// Saving user
}
How can we estimate, with Ethers.js, what the gas price will be for calling this function?
ethers.jsgas-estimategas-price
Let's say you have a function in your smart contract, like:
function saveUser(address newUser) public {
// Saving user
}
How can we estimate, with Ethers.js, what the gas price will be for calling this function?
Best Answer
First, you must get the estimated gas price to use in an empty transaction:
Then, get the estimated gas price for your specific transaction, and multiply it by
gasPrice
:Of course,
finalGasPrice
will never be exactly equal to the actual gas price you will end up paying, but it is a close enough estimate.