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.

2 Answers 2


The syntax is wrong, try in this way:

MyContract.closeBid.estimateGas("Coffee", {from: web3.eth.accounts[0]});
  • Thank you. I more doubt. I got result of 32591, is this maximum gas that the function consumes. I mean whole function including array insertion deletion etc.
    – e.k
    Mar 26, 2018 at 14:40
  • @e.k As the name implies, it's an estimate...a ballpark range based on what the function does.
    – ReyHaynes
    Mar 26, 2018 at 14:46
  • Yes, because the transaction is executed inside the VM but not mined, so that's the gas that you gonna spend. But of course in the real environment depends what price you're going to pay for that gas. Higher is the gasPrice and more fast will be mined your transaction (and more expensive gonna be to execute it) lower will be the gasPrice and less you will spend (but it could also be not mined if it's too low). Follow this link it's explained ethereum.stackexchange.com/questions/266/…
    – qbsp
    Mar 26, 2018 at 14:48

You can run estimateGas without using a contract, this is useful when you don't have the ABI but got the input data and want to estimate gas cost before submitting the transaction, or if you just don't have the method name.

From Web3.eth estimateGas docs -

    to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe",
    data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003"
> "0x0000000000000000000000000000000000000000000000000000000000000015"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.