Web3js Gas Estimate – How to Estimate Gas for a Function Using Web3 JS Only

gas-estimateweb3js

Hi this is my solidity function

function closeBid(string _product) public{
  }

I want to estimate gas for this function so in web3 js I called this like

var gas = MyContract.closeBid().estimateGas("Coffee",{from: web3.eth.accounts[0]});

But it throws InvalidNumberOfSolidityArgs(). How can I estimate gas for this function because this function consumes lot of gas. I have to make sure availability of gas for calling this function. Thank you.

Best Answer

The syntax is wrong, try in this way:

MyContract.closeBid.estimateGas("Coffee", {from: web3.eth.accounts[0]});