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.


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 '18 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 '18 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/…
    – mirg
    Mar 26 '18 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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