I'm trying to follow a tutorial for estimating the gas cost of a function.

Thus after deploying my contract I type in this code in the Remix console to get the gas estimate of calling an arbitrary funtion (substituting in my contract details):

var contractABI = [ ... ];
var contractAddress = '0xxxxx';

var contract = web3.eth.contract(contractABI);
var contractInstance = contract.at(contractAddress);

var estimatedGas = contractInstance._mint.estimateGas('0x123', '5');

I get this response in the Remix console window:

Cannot read property 'estimateGas' of undefined

Am I doing something wrong? Or is Remix unable to fully utilize web3 in the console?

  • What version of web3 are you using? It seems it is web3 v0.20. Is _mint a public or external function in your contract? – Ismael Jun 11 '18 at 19:24
  • It's an internal function; and I'm just using the web3 version that is in the Remix console down at the bottom of the page. – John DeBord Jun 12 '18 at 3:07
  • You cannot call an internal function from javascript, and estimateGas will fail. – Ismael Jun 12 '18 at 5:24

Your Answer

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

Browse other questions tagged or ask your own question.