[Ethereum] Specifying gas amount for contract call from JavaScript

contract-debuggingcontract-invocationgasout-of-gasweb3js

I'm making this call from JavaScript to the contract function.

contracts['CrowdFunder'].contract.contribute({value: web3.toWei(0.000000000000000005, 'ether')});

The function is called, but the error message says,

An error occurred during contract execution: 'Out of gas'

See http://testnet.etherscan.io/vmtrace?txhash=0x58c3e7d41db0dd3ba4c2b600b374b2576f9508d84e7351058232027af4cc3abb

How do I specify the amount of gas in JavaScript for the above?

Best Answer

Try changing

contracts['CrowdFunder'].contract.contribute({
    value: web3.toWei(0.000000000000000005, 'ether')
});

to

contracts['CrowdFunder'].contract.contribute({
    value: web3.toWei(0.000000000000000005, 'ether'), 
    gas: 100000 
});

Refer to the example under Contract Methods in JavaScript API - web3.eth.contract.

And modifying the call as suggested by eth's comment below:

contracts['CrowdFunder'].contract.contribute({
    value: 5, 
    gas: 100000 
});
Related Topic