7

I have deployed a contract to testnet which appears to function.

I have a function named contribute which gets the ether from the msg.value. The function is below and doesn't take any arguments.

I call contribute from JavaScript like this:

var res = contracts['CrowdFunder'].contract.contribute();

How do I specify ether to be sent when calling contribute?

Here is contribute which expects msg.value

function contribute() public      
    {
        contributions.push(
            Contribution({
                amount: msg.value,
                contributor: msg.sender
            }) 
        );
        totalRaised += msg.value;             
    }
eth
  • 85,679
  • 53
  • 285
  • 406
Bogdan
  • 397
  • 2
  • 8

1 Answers1

9

You pass in an object with a property named value and the amount of wei.

Using your example, like:

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

Note, in your example res will be a transaction hash.

eth
  • 85,679
  • 53
  • 285
  • 406