Suppose I have the following function:
function SetMessage (bytes32 _message) returns (bool success) {
message = _message;
return true;
}
Which might be called in Web3 as follows, for example:
MyContract.deployed().then(function (contractInstance) {
return contractInstance.SetMessage(_message, { gas: 200000, from: web3.eth.accounts[0] })
})
What is the correct syntax for using the estimateGas
function in Web3 for this function? I have seen the following example for how to use estimateGas
(here it's just checking how much gas to transfer ether from one account to another, not checking a function in a contract):
console.log(web3.eth.estimateGas({from: web3.eth.accounts[0], to: "0xEDA8A2E1dfA5B93692D2a9dDF833B6D7DF6D5f93", amount: web3.toWei(1, "ether")}))
However I'm unsure how to use estimateGas
to estimate gas for executing a function in a smart contract.