I have a contract instance:

var contract = web3.eth.contract(JSON.parse(abi)).at(address);

and I can call functions like this:


this works fine. Now I want to send some ETH with that function call. How do I do that?


Call is a local call of the function, that does not change the Blockchain state. Typically this is used for constant functions, retrieving variable values, or as a check of the function before actually invoking the real function on the Blockchain that changes state.

Since sending ETH changes state, you need to actually send the transaction to the Blockchain.

You can do this by invoking the transaction without “call”: contract.myFunction(params, { from: _senderAddress, value: _amountToSendInWei, gas: _gasLimit }).

params is optional, if your function takes in any.

And you need to make sure the _sender is authorized (ie account unlocked).

For more explanation of call vs sendTransaction, you can check this out: call vs transaction

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.