There's more...

Web3.js v1.x.x allows the user to estimate the required gas directly from the contract instance. This can be done with the help of the estimateGas method. Consider the fact that the estimation can differ from the actual utilization due to the varying state:

// Method syntax
myContractInstance
.methods
.myMethod([param1[, param2[, ...]]])
.
estimateGas(options [, callback])

// Example helloWorldInstance.methods
.changeText("Greetings!")
.
estimateGas({
from: "0xce5C2D181f6DD99091351f6E6056c333A969AEC9"

}, function(error, gasAmount){ console.log(gasAmount); });

You can also use the promise returned from the function:

// Promise
helloWorldInstance.methods
.changeText("Greetings!")
.
estimateGas({
from: "0xce5C2D181f6DD99091351f6E6056c333A969AEC9"
}) .then(function(gasAmount){ ... }) .catch(function(error){ ... });
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.19.185