Web3.js: web3js 1.0 web3.methods.mymethod.send({from:account}) needs to support sending ether

Created on 12 Sep 2017  路  8Comments  路  Source: ChainSafe/web3.js

Hi,

we are trying to send ether to an endpoint in a solidity contract, marked up with payable, i.e:

function blah(uint256 param) payable { //impl here }

In a previous version of web3.js, <0.20, this worked like so:

contractInstance.blah(param, {from:account, value:wei});

in 1.0 beta18, we can't seem to find the 'value' argument in any headers. is this supported yet? If not, how can i transact, while calling a specific contract function? The new send function looks like this:

contractInstance.methods.mymethod(param).send({from:account});

Missing the value parameter?

If this is not the correct approach please advise, i.e. are we meant to use web3.eth.sendTransaction() directly?

Thank you in advance.

Simon

clarification needed

Most helpful comment

Hey @simonmittag! I was confused by this as well, but it looks like in the send function you can pass value as one of the options for sending ether to a payable method. Something like:

contractInstance.methods.mymethod(param).send({from:account, value:wei})

Perhaps we should look into adding it to the documentation since neither of us found it.

All 8 comments

anyone?

Hey @simonmittag! I was confused by this as well, but it looks like in the send function you can pass value as one of the options for sending ether to a payable method. Something like:

contractInstance.methods.mymethod(param).send({from:account, value:wei})

Perhaps we should look into adding it to the documentation since neither of us found it.

anyone? I had the same problem..

It will look like this now:

contractInstance.methods.mymethod(param).send({from: address, value: web3.utils.toWei( value, 'ether')})

getting undefined in every possible way, Is that deprecated apI? I cannot find it in the document.

It's still not working...

Same, value not showing in metamask as of beta.37

This got fixed with the latest version of Web3.js.

Was this page helpful?
0 / 5 - 0 ratings