Sending ether from a contract to another fails

tcimolitcimoli Cagliari - ItalyMember Posts: 35
Hi, I am trying to send some ether from a contract to another, like this:
... function sendSomeMoney(uint n){; if (!secondContractAddr.send(n)) error = true; else error = false; }
secondContract is the destination contract, its address is secondContractAddr. Calling ping on secondContract works just fine, while the send returns false.

How do I know which is the problem? Is there a log to know it? For which causes a send may fail?
Thank you


  • smalltalksmalltalk Member Posts: 16
    The best way I have found for debugging is adding events on each branch of an if statement and that way you can trace the code. Crude I know but the best way I found so far. Although probably won't help you in this case.

    To send ethers to another contract you don't need to send to the contract address: ether);

    or if you want to send it via a function call you can do this: ether);

    If you have an argument to the function call then the syntax is: ether) (arg1);

  • tcimolitcimoli Cagliari - ItalyMember Posts: 35
    Thank you, it worked.
    In the fist case, usign the "call" methode, how could I also invoque the ping function?
    This is not working:;
  • smalltalksmalltalk Member Posts: 16
    Not sure what you are trying to do. The call is only required if you want to send it directly to the contract. If you want to do it via the ping function then you don't need the call, so:;

  • tcimolitcimoli Cagliari - ItalyMember Posts: 35
    edited May 2016
    Yes, thank you. I just wanted to better understand the use of call: is it possible to call a methode on a contract using call?

    I was interested also because with call, it does not throw an exception in case of failure, but it just returns a bool (so I have been told...). And I am trying to figure out how exceptions and gas consuption are managed.
Sign In or Register to comment.