5

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;             
    }
6

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.

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.