I have a function in my contract, suppose

 function foo(uint _param1) payable {
     require(msg.value == 1000);

Then I have my Javascript code:

 contract = web3.eth.contract(abi).at(address); 
 contract.foo("Hello World!", function(err, res){
   alert("Transaction sent");

Now, I have the web3 injected by Metamask, so I must use the asynchronous method because MetaMask doesn't support the synchronous method without the callback. I have tried several ways to add an amount to my transaction, e.g. I've tried

 contract.foo("Hello World!",
   {from: web3.eth.coinbase, value: 1000}, 
   function(err, res){
    alert("Transaction sent");

but there is nothing that works!

So, how to solve it?

  • What you tried looks right to me. What happened when you tried it?
    – user19510
    Mar 7 '18 at 2:34
  • MetaMask opens the popup that asks the confirmation but the value is set equal to zero Ether. Mar 7 '18 at 10:35

From your description, this is probably just a rounding error. The amount of you're sending is 1000 wei, which is 0.000000000000001 ether. From your description, it sounds like you're looking for the value in MetaMask, which I believe displays fewer decimal points than that.

Try sending a (much) higher value to confirm.

  • You are right... So stupid error... Mar 7 '18 at 17:38

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.