I was wondering if the pattern below is correct for sending a transaction with the correct gas limit.

this.contracts.myContract.methods.myMethod.getEstimatedGas().then(gas => {
    ["prop1", "prop2"],

I've also read that adding 10% to the estimate could be sensible.

Or should I just go with whatever prices Metamask populates when making the method call?

2 Answers 2


You can estimate the gas cost of your transaction using web3.eth.estimateGas.


var result = web3.eth.estimateGas({
to: "0xc4abd0339eb8d57087278718986382264244252f", 
data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003"
console.log(result); // "0x0000000000000000000000000000000000000000000000000000000000000015

I would take this estimate and multiply by a factor of 1.1 to be safe.

See https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethestimategas for further reference.

  • I am indeed using the web3.eth.estimateGas method, I should have been clearer in my original question and code. I've updated the question now :) Jun 28, 2018 at 11:38

I use to follow this pattern that should be useful:

await contractInstance.methods.transfer(self.state.owner, self.state.value)
            from: accounts[0],
            gas: '5000000'

With gas you are setting up the gasLimit.

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.